Search code examples
bitmapiso8583

Nth Bit to BitMap Conversion


I am reading Nth Bit to BitMap Conversion from here BitMaps

I want to understand how they are mapping n-th bit(Integers ranging from 0-9) to bit map(0 and 1), below is the code copied from there:

0________10________20________30________40________50________60__64
1234567890123456789012345678901234567890123456789012345678901234  n-th bit
0100001000010000000000000001000100000010110000000100100000000100  bit map

Also, they are converting '82x is binary '1000 0010' , but when I calculated binary of 82 is coming as 1010010.

Any help will be appreciated.

Thanks, Arpit


Solution

  • Ok, ignore the n-th bit data for a moment. Suppose the example just had the bit map.

    0100001000010000000000000001000100000010110000000100100000000100

    From the bitmap you can see that the first field is not in the message (because the first bit in the bitmap is 0), and the second field is present in the message (because the second bit is 1), and so on. Suppose for example you wanted to find out if the 56th field was in the message, you would have to count the bits in the bitmap until you got to the 56th bit and then see whether it was 0 or 1.

    The example would be easier to understand if they also showed you the position of the bits in the bitmap, so you would not have to count bits. The n-th bit data in the message is just counting the bits for you. Lets look at the first 9 n-th values first.

    123456789
    0100001000010000000000000001000100000010110000000100100000000100
    

    As you can see the n'th bit data is just counting the first 9 bits. You can easily see that the 6-th bit is 0 and the 7-th bit is 1 without counting bits. So what about the 10-th bit.

    The example can't show the 10-th bit like this

    12345678910
    0100001000010000000000000001000100000010110000000100100000000100
    

    because 10 is two digits and is above both the 10-th and the 11-th bit in the bitmap. To solve this problem, you can write 10 vertically like this

             1
    1234567890
    0100001000010000000000000001000100000010110000000100100000000100
    

    and write the example as

    0000000001111111111222222222233333333334444444444555555555566666  n-th  
    1234567890123456789012345678901234567890123456789012345678901234  bit
    0100001000010000000000000001000100000010110000000100100000000100  bit map
    

    Some people will write this as

    0        1         2         3         4         5         6      n-th
    1234567890123456789012345678901234567890123456789012345678901234  bit
    0100001000010000000000000001000100000010110000000100100000000100  bit map
    

    The example you gave, has the n-th bit information in a slightly different way but it means the same thing.

    Now, to answer the second part of your question, why 82x converts to 100000010? The 82 is in base 16 and not base 10.