This commit is contained in:
Rushil Umaretiya 2024-03-08 23:53:54 -05:00
parent c483dc942d
commit 991bede316
No known key found for this signature in database
GPG Key ID: 4E8FAF9C926AF959

View File

@ -1,4 +1,4 @@
// PID: 9DigitPidNoSpacesOrDashes
// PID: 730677144
// I pledge the COMP 211 honor code.
/**
@ -11,28 +11,37 @@
#include "bit_utils.h"
unsigned int mask(unsigned int num, unsigned int bits) {
// TODO: implement
return 0;
return num & bits;
}
unsigned int set(unsigned int num, unsigned int bits) {
// TODO: implement
return 0;
return num | bits;
}
unsigned int inverse(unsigned int num, unsigned int bits) {
// TODO: implement
return 0;
return num ^ bits;
}
unsigned int bit_select(unsigned int num,
unsigned int startbit,
unsigned int endbit) {
// TODO: implement
return 0;
unsigned int shifted = num >> endbit;
unsigned int bit_count = startbit - endbit + 1;
unsigned int mask = (1 << bit_count) - 1;
return shifted & mask;
}
unsigned int barrel_shift(unsigned int num, unsigned int shamt) {
// TODO: implement
return 0;
const unsigned int bit_width = sizeof(unsigned int) * 8;
shamt %= bit_width;
if (shamt == 0) {
return num;
}
unsigned int right_part = num >> shamt;
unsigned int left_part = num << (bit_width - shamt);
return right_part | left_part;
}