lua-users home
lua-l archive

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

I am having no trouble at all using Lua to manipulate bytes according to PIL but on P198 it says

'you can even do pattern matching over binary data'

I would like to be able read and manipulate bits not bytes.

The code below manipulates a few "1"'s but should change thousands.

bin ='29fb.bin', 'r') --29fb is 512 KB I am on Linux no "rb"
bin_all = bin:read("*all")
bin_zero, ntimes  = bin_all.gsub(bin_all, '1', '0')

print(ntimes) --> 20 --should be way more times then this

Is there also a way to convert binary to hex in pure Lua, I know Mike Pall has a great library but it is there a way to do this in pure Lua?

Is there also a way to read one bit? read(1) is one byte, is there a way to read one bit?

Thanks for reading-Patrick