Old World Macs
BinDecHex.lua is the result of this effort. The conversion functions have been tested extensively against decoding PowerPC 4 byte instructions for the upcoming "ldis," a Lua-based BSD-licensed replacement for objdump and otool. BinDecHex contains the following Big-endian functions:
These convert binary<->decimal<->hexadecimal
Dec2Bin(s [, num])
With the exception of Dec2Bin, each function takes the value (as a string) and converts it, returning a string. Dec2Bin optionally takes a number indicating how many bits to extend the string.
These do And, NAnd, OR, XOR, and Not (NOTE: BMAnd and BMOr are well tested, the others less tested)
The first parameter is the value (a hex string), and the second is the mask (also a hex string). BMNot toggles bits (off to on, on to off) as specified by the mask and leaves the rest alone.
These functions shift right and left, adding zeros to lost or gained bits returned values are 32 bits long (fully tested):
nb specifies the number of bits to shift in either direction.
In order to use the functions, you have to "require" them. Enter Lua and then type
> require "BinDecHex"
Then, each function is accessed through the table BinDecHex.
> print(BinDecHex.Hex2Dec("100")) 256 >