-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitmap.cpp
More file actions
38 lines (36 loc) · 880 Bytes
/
bitmap.cpp
File metadata and controls
38 lines (36 loc) · 880 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
31
32
33
34
35
36
37
38
#include <stdio.h>
void displayArray(int array[], int size){
printf("the array is:");
int i;
for(int i = 0; i < size; i++){
printf(" %d", array[i]);
}
printf("\n");
}
void displayBitmap(unsigned char bitmap[], int bitMapSize){
unsigned char mask = 0x1;
int i, j;
printf("this result array is:");
for(int i = 0; i < bitMapSize; i++){
for(j = 7; j >= 0; j--){
if((bitmap[i] & (0x1<<j))!=0){
printf(" %d", i*8+(7-j));
}
}
}
printf("\n");
}
void createBitmap(unsigned char bitmap[], int bitMapSize, int array[], int arraySize){
int i = 0;
for(i = 0; i < arraySize; i++){
bitmap[array[i]/8] = bitmap[array[i]/8]|(0x1<<(7-array[i]%8));
}
}
int main(void){
int array[10] = {34,45, 1, 39, 21, 68, 65, 100, 4, 51};
displayArray(array, 10);
unsigned char bitmap[13] = {0};
createBitmap(bitmap, 13, array, 10);
displayBitmap(bitmap, 13);
return 0;
}