View Single Post
  #3 (permalink)  
Old February 24th, 2004, 12:30 PM
davekw7x davekw7x is offline
Authorized User
 
Join Date: Feb 2004
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Note "minor" typo in the previous post:
  for(int i=0;i,4;i++)
should be
  for(int i=0;i<4;i++)


Now, using the formatted output function, fprintf(),
means that the file will contain the ASCII representation
of the numbers expressed in decimal (each number has a
value of 1431655765 in your example). Note that the size
of the file is 40 bytes (four 10-digit decimal numbers in
this case). In general, for different data, since the decimal
digits are all run together, it would not be possible to
read back the file to reproduce the original data (unless you
already knew what the data was).


If you want to write the four 32-bit numbers as binary bits,
try the function fwrite().

That is, instead of
  fprintf(dude, "%d", d);
try
  fwrite(&d, 4, 1, dude); // write one four-byte word as bits

Now, the output file has a size of 16 bytes (four 32-bit words).
Exactly 128 bits, which is the size of the data you are
representing.

Dave

Quote:
quote:Originally posted by [email protected]
 hi

use bit wise operators
  & and <<


// note declare the integer d as 32bit long integer.

d = 0;
int swap_a[4][32];


for(int i=0;i,4;i++)
{
d =0;
for(int j=0;j<32;j++)
{
 d = d << 1; // shift bits left 1 position
 d = d | swap_a[i][j];
}
fprintf(dude, "%d", d);
}

// note the resulting the file will contain only the 4 integers
Reply With Quote