lua-users home
lua-l archive

Re: Counting records in a binary file

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Sep 15, 2008 at 11:13 AM, Jeff Wise <jwise@sealyrealty.com> wrote:
>> - convert bytes 2,3 to a number 'N'
>> - skip N bytes
>
> I'm sorry, but I have no clue how to convert bytes 2,3 to a number, nor how to skip N bytes. Can you elaborate, perhaps a code snippet?
(really untested):
local count = 0
local offset = 0
while offset < strlength do
 assert (string.byte(s,offset+1) == 0x5A, 'no header')
 count = count+1
 local b2,b3 = string.byte (s, offset+2, offset+3)
 offset = offset + b2*256+b3
end
-- 
Javier

AltStyle によって変換されたページ (->オリジナル) /