Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org C, read 8 bit octal numbers, convert to 24 bit binary
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 01-20-2004, 08:03 AM #1 bamalabs LQ Newbie   Registered: Jan 2004 Location: Alabama Distribution: Slackware Posts: 10 Rep: C, read 8 bit octal numbers, convert to 24 bit binary I'm need to read a file containing 8 columns of 8 bit octal numbers, and convert to 24 bit binary string. No experience here. Do I have to convert from octal to decimal, then decimal to binary? If so, any hints as to how to do this? Any help appreciated.
 01-20-2004, 09:32 AM #2 jtshaw Senior Member   Registered: Nov 2000 Location: Seattle, WA USA Distribution: Ubuntu @ Home, RHEL @ Work Posts: 3,892 Blog Entries: 1 Rep: strtol will take a string with a number in it and convert it to a long int. You would set the base argument to 8 in your case. It's function prototype looks as follows: #include long int strtol(const char *nptr, char **endptr, int base); Reading the man page on this (man strtol) will tell you more. The manual pages are also available on-line at numerous different places. As far as converting it to binary, I'll leave that to you, this sounds suspiciously like a school project
 01-20-2004, 09:55 AM #3 bamalabs LQ Newbie   Registered: Jan 2004 Location: Alabama Distribution: Slackware Posts: 10 Original Poster Rep: Nope, not a school project. Actually a work project. I think I can handle the conversion to binary, though. I hadn't heard of strtol before, so thanks for your help.
 01-20-2004, 09:59 AM #4 jtshaw Senior Member   Registered: Nov 2000 Location: Seattle, WA USA Distribution: Ubuntu @ Home, RHEL @ Work Posts: 3,892 Blog Entries: 1 Rep: Ya, I haven't seen a built in function that does it, but shoudl be easy to do some moding in a for loop and build a string with the binary. Glad I could offer some assistance.

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Hello123 Linux - Hardware 2 09-14-2005 05:50 AM static_drc Linux - Software 2 06-29-2005 01:21 PM Kaj Linux - Software 1 12-13-2004 09:43 AM yrraja Linux - Hardware 2 04-30-2003 06:41 AM yrraja Linux - General 4 04-29-2003 11:54 PM

All times are GMT -5. The time now is 06:51 AM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -