[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Reading binary files
- From: "Jeff Wise" <jwise@...>
- Date: Mon, 15 Sep 2008 08:48:49 -0500
I'm reading a file in binary mode. Each "record" of this file begins with
X'5A'. Immediately after this first byte is a 2 byte length, i.e. a signed
16 bit integer. This is Lua from the DOS box on Windows. I used this:
--
local hex5A = 'Z'
-- other code
_, count5A = string.gsub(bytes, hex5A, hex5A)
--
This works becaue X'5A' is coincidentally 'Z'. I could not get
local hex5A = 0x'5A'
to work. What gives?
My main question is how to index from the first record to the next record.
This record begins at the first byte (X'5A') + the 2-byte length + 1.
The problem is that the data which is "image data" may contain X'5A' records
so my count code above is counting all '5A' bytes instead of just the
"beginning of record" bytes.