mirror of
https://github.com/Comp211-SP24/lab-04-Rushilwiz.git
synced 2025-04-03 03:40:20 -04:00
30 lines
724 B
C
30 lines
724 B
C
// Do not edit this file
|
|
|
|
#include "bit_utils.h"
|
|
|
|
unsigned int mask(unsigned int num, unsigned int bits) {
|
|
return num & bits;
|
|
}
|
|
|
|
unsigned int set(unsigned int num, unsigned int bits) {
|
|
return num | bits;
|
|
}
|
|
|
|
unsigned int inverse(unsigned int num, unsigned int bits) {
|
|
return num ^ bits;
|
|
}
|
|
|
|
unsigned int bit_select(unsigned int num,
|
|
unsigned int startbit,
|
|
unsigned int endbit) {
|
|
startbit++;
|
|
num <<= (SIZE - startbit);
|
|
num >>= (SIZE - startbit + endbit);
|
|
return num;
|
|
}
|
|
|
|
unsigned int barrel_shift(unsigned int num, unsigned int shamt) {
|
|
unsigned int right_bits = num << (sizeof(unsigned int) * 8 - shamt);
|
|
return (num >> shamt) | right_bits;
|
|
}
|