Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!talisker.lacave.net!lacave.net!not-for-mail From: 7stud -- Newsgroups: comp.lang.ruby Subject: Re: Binary file: SAT Date: Wed, 20 Apr 2011 19:02:19 -0500 Organization: Service de news de lacave.net Lines: 27 Message-ID: <4fa8adc3b92c44287a399f6cb1aab3ff@ruby-forum.com> References: NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: talisker.lacave.net 1303344290 58424 65.111.164.187 (21 Apr 2011 00:04:50 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Thu, 21 Apr 2011 00:04:50 +0000 (UTC) In-Reply-To: X-Received-From: This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway X-Mail-Count: 381962 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: <4fa8adc3b92c44287a399f6cb1aab3ff@ruby-forum.com> Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:3278 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/.