Binary Data
If I want to read binary data in a char it comes out like 0x00
Is there anyway to get it to output something like 101011?
Yes.
I had a program that would do this, but I lost it during my latest hard-drive format. Its not too difficult, however.
Basically, you have a macro like so:
#define BITX(x) (x<<1)
(^The above is probably incorrect... Its meant to reference each bit.. i.e, BITX(4) would be the bit in location 4.)
then you loop through the byte and test if each bit is set (using &), then print out a 1 or 0 depending on its state.
Its been a long time since I did any bit-fiddling stuff, so my appologies if I left anything out, or if my description had any errors.
I had a program that would do this, but I lost it during my latest hard-drive format. Its not too difficult, however.
Basically, you have a macro like so:
#define BITX(x) (x<<1)
(^The above is probably incorrect... Its meant to reference each bit.. i.e, BITX(4) would be the bit in location 4.)
then you loop through the byte and test if each bit is set (using &), then print out a 1 or 0 depending on its state.
Its been a long time since I did any bit-fiddling stuff, so my appologies if I left anything out, or if my description had any errors.
Ah, thanks!
Looking back at the macro I posted before... ugh.. it just multiplies by two...doh.
Looking back at the macro I posted before... ugh.. it just multiplies by two...doh.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement