forked from rkwong43/NUFS-Filesystem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitmap.c
More file actions
32 lines (27 loc) · 629 Bytes
/
Copy pathbitmap.c
File metadata and controls
32 lines (27 loc) · 629 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "bitmap.h"
#include <stdio.h>
#include <stdint.h>
// This was given starter code.
/*
* Puts the given element at the given index.
* Takes in the bitmap, the index, and number to put.
*/
void bitmap_put(void* bm, int ii, int vv){
int byte = ii / 8;
int bit = ii % 8;
if (vv == 0) {
((uint8_t*)bm) [byte] &= ~(1 << (ii & 7));
} else {
((uint8_t*)bm) [byte] |= 1 << (7 - (bit));
}
}
/*
* Returns the element at the given index.
* Takes in the bitmap and an index
*/
int bitmap_get(void* bm, int ii) {
int byte = ii / 8;
int bit = ii % 8;
uint8_t* bmu = bm;
return ((bmu[byte] >> 7 - bit) & 0x01);
}