[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: manipulating bits not bytes-Enthusiasts level question
- From: "Patrick Mc(avery" <spell_gooder_now@...>
- Date: Sat, 04 Sep 2010 09:15:08 -0400
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 = io.open('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