Re: [CocoaProgrammingForAbsoluteBeginners] Accessing 8-bit bytes from a file using Cocoa
Re: [CocoaProgrammingForAbsoluteBeginners] Accessing 8-bit bytes from a file using Cocoa
- Subject: Re: [CocoaProgrammingForAbsoluteBeginners] Accessing 8-bit bytes from a file using Cocoa
- From: Paul Lynch <email@hidden>
- Date: Mon, 1 May 2006 13:29:52 +0100
The C solution is to define your oneByte as unsigned char. This
doesn't affect how it is read in, but affects how the character is
interpreted when converted (such as for output).
The Cocoa approach would be to read all of the input file into an
NSData, and then reference bytes within the data object. In some
ways, the Cocoa approach is more complicated - because it makes less
assumptions about your data; you have assumed that your data is old
style ascii, and have discovered by accident that even plain ascii
can have many different encodings.
Paul
On 1 May 2006, at 13:17, Phil Faber wrote:
Hi.
I want to be able to read from any file type (.txt, .doc, .xls,
etc) one 'literal byte' (that is, a string of eight ones-and-zeros)
at a time. The file could be any size. For each byte I want to be
able to get the actual ASCII value of that byte (a number from zero
to 255). (I know that some data has to be represented by one, two
or four bytes but I am particularly interested in accessing each 8-
bit byte one at a time.)
At the moment, I'm using C coding:
(fread(&oneByte,1,1,fp1) [where oneByte is defined as a 'char']
..to read in each byte but:
(a) this only works for basic ASCII characters (for example, "A"
appears as ASCII 65) but not non-standard characters (for example,
"å" appears as ASCII -116 ... yes, MINUS 116)
(b) I suspect that it is better to achieve this task with Cocoa
instead of C.
Can anyone please provide me with the most basic coding to achieve
this in Cocoa?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden