mirror of
https://github.com/Comp211-SP24/lab-03-Rushilwiz.git
synced 2025-04-03 03:20:16 -04:00
finihsed
This commit is contained in:
parent
c483dc942d
commit
991bede316
31
bit_utils.c
31
bit_utils.c
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user