Posted 25 November 2015 - 11:48 AM
I realized LUA did not have the required capabilites of converting into complete binary, so I made my own API.
LUA can utilize string.byte to transform "H" to "104" but it can not convert directly to bits, or so I could not find.
Capabilities/functions:
byte2binary:
Pass it a single byte (such as 104) and it will convert it into its corresponding 8 bit binary number (such as 01101000).
binary2byte:
Pass it a complete binary number (max. 8 digits, example 01101000) and it will convert it to the corresponding byteform (104)/
string2bytes:
Pass it a string (such as "HHH") and it will break it up into an array of bytes, such as ("104104104".
string2binary:
Pass it a string (such as "HHH") and it will convert it into a binary string ("011010000110100001101000")
bytes2stringArr:
Pass it an array of bytes ({"104","104"}) and it will convert it into an array of strings ({"H","H"})
binary2string:
Pass it a full binary string (011010000110100001101000) and it will convert it into an ascii string ("HHH")
The capabilities to further split these strings or arrays into desired divisions are easily implemented, but I don't need them, so I didn't.
113 lines of code without the leading comments
http://pastebin.com/Bw9rpLPn
this probably isn't well optimized, by the way, this is just what I threw together to suit my needs at 5am..
LUA can utilize string.byte to transform "H" to "104" but it can not convert directly to bits, or so I could not find.
Capabilities/functions:
byte2binary:
Pass it a single byte (such as 104) and it will convert it into its corresponding 8 bit binary number (such as 01101000).
binary2byte:
Pass it a complete binary number (max. 8 digits, example 01101000) and it will convert it to the corresponding byteform (104)/
string2bytes:
Pass it a string (such as "HHH") and it will break it up into an array of bytes, such as ("104104104".
string2binary:
Pass it a string (such as "HHH") and it will convert it into a binary string ("011010000110100001101000")
bytes2stringArr:
Pass it an array of bytes ({"104","104"}) and it will convert it into an array of strings ({"H","H"})
binary2string:
Pass it a full binary string (011010000110100001101000) and it will convert it into an ascii string ("HHH")
The capabilities to further split these strings or arrays into desired divisions are easily implemented, but I don't need them, so I didn't.
113 lines of code without the leading comments
http://pastebin.com/Bw9rpLPn
this probably isn't well optimized, by the way, this is just what I threw together to suit my needs at 5am..
Edited on 25 November 2015 - 08:49 PM