
January 6th, 2013, 06:25 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 2
Time spent in forums: 53 m 19 sec
Reputation Power: 0
|
|
|
Create a character bitmap (Used in ISO8583 Standard)
In C books I see the bits arranged in the way as below.
[7|6|5|4|3|2||1|0] (0th bit on the right)
When I insert the value and check the bits which are 1, I am a bit confused.
[B2]
01001101
--Till here I am OK as the bits are arranged from right to left.
But when I check the bits for ON or OFF (source given below) it is checking from left to right.
Bit [01] is OF
Bit [02] is ON
Bit [03] is OF
Bit [04] is OF
Bit [05] is ON
Bit [06] is ON
Bit [07] is OF
Bit [08] is ON
I was expecting as
[0|1|0|0|1|1|0|1]
[7|6|5|4|3|2|1|0] (Which means, when I check for Bit at location 0, it should say ON where as in reality it shows OF).
Code:
void check_bit_char(unsigned char character)
{
int bitchecker = 0;
char mask_char = 0x1;
int size_char = sizeof(char);
for(bitchecker=0;bitchecker<size_char*8;bitchecker++)
{
if(character & (mask_char<<bitchecker))
printf("1");
else
printf("0");
}
puts("\n");
for(bitchecker=0;bitchecker<size_char*8;bitchecker++)
{
if(character & (mask_char<<bitchecker))
printf("Bit [%02d] is ON\n", bitchecker+1);
else
printf("Bit [%02d] is OF\n", bitchecker+1);
}
puts("\n");
}
void check_bit_bitmap(unsigned char *bitmap)
{
}
int main()
{
unsigned char source_char = 0xB2;
printf("[%02X]\n", source_char);
check_bit_char(source_char);
}
I am trying to create a character bitmap in ISO8583 format. Here I will have an unsigned character array where each bit corresponds to a field. If the bit is 1, the corresponding field is exected.
|