#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    2
    Rep 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.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,064
    Rep Power
    9398
    bitchecker counts from 0 to 7. That means it'll print bit 0 first and bit 7 last. If you want it to print MSB->LSB then reverse the direction of the loop.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by requinix
    bitchecker counts from 0 to 7. That means it'll print bit 0 first and bit 7 last. If you want it to print MSB->LSB then reverse the direction of the loop.
    As a matter of fact, I tried the reverse loop and it worked. But I was a bit doubtful on whether I was correct. Hence the post.

IMN logo majestic logo threadwatch logo seochat tools logo