Alessandro Barracco wrote in post #994136:
> Hi all. I never work before with binary file, and I'm a bit
> confused.....
>

Both numbers and characters are stored as integers in file(or anywhere 
on a computer).  One method of storing characters in a file is with the 
ASCII encoding.  For instance, in the ASCII encoding 'a' is stored as 
the integer 67, taking up one byte total.  Note that you could also 
store the integer 67 in 4 bytes--the other three bytes would just be all 
0's.

You may also want to store the count of the number of banks in New York, 
which is 67.  You could also store that in one byte.  So the question 
becomes, how do you know whether a 67 you read from the file is supposed 
to be the count of banks or the letter 'a'?  The answer is: you have to 
know how the data in the file is supposed to be interpreted.

If the integer in the first byte in a file is supposed to be an integer, 
than you read in the integer as is; and if the integer in the second 
byte in the file is supposed to be a letter, then you need to convert 
the integer to a letter.  In other words, you have to know what each 
byte in the file is supposed to represent.

-- 
Posted via http://www.ruby-forum.com/.