LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 01-20-2004, 08:03 AM   #1
bamalabs
LQ Newbie
 
Registered: Jan 2004
Location: Alabama
Distribution: Slackware
Posts: 10

Rep: Reputation: 0
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.
 
Old 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: Reputation: 66
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 <stdlib.h>

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
 
Old 01-20-2004, 09:55 AM   #3
bamalabs
LQ Newbie
 
Registered: Jan 2004
Location: Alabama
Distribution: Slackware
Posts: 10

Original Poster
Rep: Reputation: 0
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.
 
Old 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: Reputation: 66
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Which version of 32 bit redhat will install on IBM xSeries 366 (64 bit)? Hello123 Linux - Hardware 2 09-14-2005 05:50 AM
Convert to 16 bit bitmap static_drc Linux - Software 2 06-29-2005 01:21 PM
Compiling 32-bit binary in a 64-bit environment Kaj Linux - Software 1 12-13-2004 09:43 AM
Graphic Card that Supports displaying 8-bit and 24-bit images simultaneously yrraja Linux - Hardware 2 04-30-2003 06:41 AM
Displaying 8-bit images in 24-bit mode and vice versa yrraja Linux - General 4 04-29-2003 11:54 PM


All times are GMT -5. The time now is 08:46 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration