lab-04-Rushilwiz/bit_utils.c
github-classroom[bot] 19a7e4ec2d
Initial commit
2024-03-20 22:21:48 +00:00

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;
}