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.
|
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:) |
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.
|
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. |
All times are GMT -5. The time now is 11:21 PM. |