C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 6th, 2013, 06:25 AM
adarsh nanu adarsh nanu is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 adarsh nanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #2  
Old January 6th, 2013, 06:45 AM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,716 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 20 m 33 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to 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.

Reply With Quote
  #3  
Old January 6th, 2013, 12:26 PM
adarsh nanu adarsh nanu is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 adarsh nanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m 19 sec
Reputation Power: 0
Quote:
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Create a character bitmap (Used in ISO8583 Standard)

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap