|
From: Robert A. <ral...@gm...> - 2005-07-03 14:57:14
|
Two points.... first is everything in computers is binary.. even the Text of this e-mail, everything above that depends on how you interpet the data. (the following excludes unicode which complicates plain text but...read one= ) Even in a 'plain text' file the Text is really ASCII where 'A' is 65, etc.= .. that 65 is not stored are the digit 6 followed by 5 because neither 6 nor 5 are binary.... everything has to be stored as a series of zeros and ones ... usually (and this again depends upon interpetation) they are handled in series of 8 bits ( a series of 8 zeros and/or ones) which allow the binary numbers which correspond to the decimal numbers 0 to 255. So your problem has 3 sub problems... 1 to read the file=20 2 to interpet the data as binary 3 to print it out Focusing on part 2... most of the options to read data will return you a byte (8 bits long) which you will usually work with as a numerical value ranging from 0 to 255. I will assume that you know how to convert from decimal to binary(if you don't let me know and I can explain the two different methods I know...if you can't follow the one you should be able to follow the other). You could do something as simple and as long as a huge if/them/else or preferably CASE statement where you do something like: switch (i) case(0) : std::cout << "00000000" ; break case(1): std::cout << "00000001" ; break ... ... Or you could do someting as complicated as use an algorithm to do a conversion and print out the values as strings.. Or alterbatively there is probably a modifier to std::out to change the output base to binarty... hope this helps, Robert On 7/3/05, Scott <fre...@ve...> wrote: > =20 > Does anyone, or can anyone help me write a simple console app,=20 > to scan a file and dump or display it's contents as "Decimal 1 byte bina= ry" > even just some info, on what i would do to view a file as decimal 1byte..= .=20 > would help,=20 > =20 > i.e=20 > =20 > I want to display or dump to a text file something like...=20 > the following:=20 > ---------------------------------------------------------------- > 00000020 105 100 0 0 76 65=20 > 00000040 84 83 0 0 0 0=20 > 00000060 0 6 86 77 65=20 > ---------------------------------------------------------------- > Anyone have any links, or where i should be looking for more info,=20 > i have done google searches without much luck.=20 > =20 > Thanks,=20 >=20 > Cheers,=20 > Scott.=20 > =20 > =20 > |