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 support@ccsinfo.com

converting HEX value to OCTAL

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







converting HEX value to OCTAL
PostPosted: Wed Oct 06, 2004 2:37 am     Reply with quote

Hi

I'm trying to convert a hex number e.g 0x147F1E into its octal format so it can be displayed as 5077436. Anybody any ideas.

Cheers
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Oct 06, 2004 4:55 am     Reply with quote

I am assuming for some reason you can't use printf routines to do it for you. In which case all you need to do is shift left or right (depending on wherether or not you want most or least significant digit first) three bit positions at a time. Each three bits give you the octal value. Repeat this process 8 times to give you all 24 bits.

Code:

long k = 0x147F1E;
int i,j ;

for (i = 0; i<8 ;i++)
   {
    j := k & 0x7;
    k = k >> 3;
    // now do something with j......
   //..
   }
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