This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
cmdpwnd's profile picture

bit lib on binary

Started by cmdpwnd, 28 May 2015 - 07:57 PM
cmdpwnd #1
Posted 28 May 2015 - 09:57 PM
Right now I have made my own funcs to do bitwise and + not but then I saw the bit library and tried to use it but it doesn't work how I imagined, it returns a large decimal instead of the binary bit and so my question is actually a few.

First: how to do bitwise AND on binary number using the bit32 library.
10110111
11000100 = 10000100

Second: How to calculate the ipv4 broadcast address by adding the network address and the wildcard mask in binary form using the bit32 library
192.168.1.0 + 31 = 192.168.1.31

11000000.10100000.00000001.00000000
00000000.00000000.00000000.00011111 = 11000000.10100000.00000001.00011111
Creator #2
Posted 28 May 2015 - 10:34 PM
Hello, nice to see you here. I have that issue too.
Bomb Bloke #3
Posted 28 May 2015 - 11:44 PM
10,110,111 is ten million, one hundred and ten thousand, one hundred and one. AND that with eleven million one hundred and yeah, you'll probably get a big number back.

On the other hand, bit.band(183, 196) (or bit32.band, if you want to be all Lua 5.2 about it) would give you 132. In short, Lua uses base 10 for numeric representations.

You can enter hex representations of numbers if you stick a 0x in front of them - for example, bit.band(0xB7, 0xC4) would also be valid - but to the best of my knowledge, base two representations aren't an option.