[OT] C help plz..

2000-03-16 Thread Shao Zhang
Hi, If I have an unsigned long int, instead printing out its values in string using printf(%ld\n, my_var), I would like to print it out as a 4-byte binary data. Is there any easy way to do this in C. Thanks. Shao. --

Re: [OT] C help plz..

2000-03-16 Thread Shao Zhang
But isn't %[Xx] just prints out as Hexdecimal? I just tried, and it prints out something like: 38c9616e which consumes 8 bytes in a file. Given that unsigned long is 32 bits, I want to use exactly 4 byte to represent it in order to save some space. Thanks. Shao. Matthew Dalton [EMAIL

Re: [OT] C help plz..

2000-03-16 Thread Eric G . Miller
On Thu, Mar 16, 2000 at 03:04:53PM +1100, Shao Zhang wrote: Hi, If I have an unsigned long int, instead printing out its values in string using printf(%ld\n, my_var), I would like to print it out as a 4-byte binary data. Is there any easy way to do this in C.

Re: [OT] C help plz..

2000-03-16 Thread Matthew Dalton
Sorry... I automatically made a link between binary data and hexadecimal data... You could shift 8 bits of the unsigned long into a unsigned char one at a time, and print that character with a %c in the printf, or use putchar() or something. eg: unsigned long l = 0x38c9616e;

RE: [OT] C help plz..

2000-03-16 Thread Lewis, James M.
You could just do: fflush (stdout); /* clear the stream buffer */ write (1, myvar, 4); /* write binary to stdout */ jim Thanks. This is exactly what I want. I have thought about doing it this way, it is just that from memory, there is a libc function that does the equivalent.

Re: [OT] C help plz..

2000-03-16 Thread Sean 'Shaleh' Perry
On 16-Mar-2000 Shao Zhang wrote: Thanks. This is exactly what I want. I have thought about doing it this way, it is just that from memory, there is a libc function that does the equivalent. What was given is the only safe and sane way I have ever seen. Bigger question is why do you have a