I am trying to create a bitmap of 100 1s and 0s.
Below is what i came out so far.. I having issue printing the bitmap or rather i do not know how to print the bitmap.
I want to display the bitmap that consist of all the 1 and 0 that i had set. for index 0 to 99
int main()
{
unsigned int bit_position, setOrUnsetBit, ch;
unsigned char bit_Map_array_index, shift_index;
unsigned char bit_map[100] = { 0 };
do
{
printf("Enter the Bit position (bit starts from 1 and Ends at 100) \n");
scanf("%d", &bit_position);
printf(" Do you want to set/unset the Bit (1 or 0) \n");
scanf("%d", &setOrUnsetBit);
bit_Map_array_index = (bit_position - 1) / 8;
shift_index = (bit_position - 1) % 8;
printf("The bit_position : %d shift Index : %d\n", bit_position, shift_index);
if (setOrUnsetBit)
{
bit_map[bit_Map_array_index] |= 1 << shift_index; //set 1
}
else
{
bit_map[bit_Map_array_index] &= ~(1 << shift_index); //set 0
}
printf(" Do You want to Continue then Enter any Number"
"and for Exit then enter 100\n");
scanf("%d", &ch);
} while (ch != 100);
//I wan to print bitmap here after exiting
system("pause");
return 0;
}
I have very little experience in C programming... So correct me wherever i am wrong.
Thanks in advance.