CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

String Binary to hex number

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
chingB



Joined: 29 Dec 2003
Posts: 81

View user's profile Send private message

String Binary to hex number
PostPosted: Thu Jul 08, 2004 8:01 am     Reply with quote

Hello,

Anyone has a snippet on how to convert a string binary say "11000011" to C3 as hex number.

Any help will do.

thanx
Guest








Base Conversions
PostPosted: Thu Jul 08, 2004 8:13 am     Reply with quote

I searched on binary AND hex AND convert to find the following. Try using Search one day, it might save you (and US) a lot of time!

http://www.ccsinfo.com/forum/viewtopic.php?t=16173

I checked back in the forum and found you keep asking repeated questions over an over about conversions between the bases. I would recommend paying attention to what you are being told and learn how to do this rather than trying to get us to do the work every time (Maybe read up on it!)
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu Jul 08, 2004 1:21 pm     Reply with quote

This is 100% untested and off the top of my head so it may not even compile:

Code:

// st is character array containing binary number of interest
// example st[] = "01011010" which is 0x5A
// i is int8 and result is int16
i=0;
result = 0L;
do {
   shift_left(&result,2,st[i]-'0');
} while(st[++i]);


Add a more detailed stop condition to the do-while loop to prevent more than 16 characters from being evaluated, or whatever is appropriate for your data set.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group