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

Decbinhex API - Convert decimal numbers to binary and hexadecimal

Started by Jajnick, 08 October 2012 - 07:21 PM
Jajnick #1
Posted 08 October 2012 - 09:21 PM
Hello.
Today I'd like to present you Decbinhex - incredibly simple and useless API I wrote because I was bored. As its name suggests, it converts decimal numbers to binary and hexadecimal. It is available on Pastebin, under ID xzgAyfD9. In fact, I don't really expect any replies to this thread, but whatever.

It's very easy in use, as it offers only two functions: bin and hex, whose usage is obvious. It doesn't support converting numbers back to decimal, because it's already implemented in Lua (the tonumber function). Please note: Trying to convert fractions or negative numbers may result in errors. The API is meant to only return human-readable Base-2 and Base-16 representations of given Base-10 numbers. You must find your own way to represent negative values and fractions, sorry.
Anyways, I seriously hope that someone will find this helpful, although I wrote this in like… 10 minutes, lol.
Orwell #2
Posted 09 October 2012 - 05:30 AM
You get a reply after all :D/>/> I just want to point out that for the hexadecimal representation you can do:

string.format("%X",1337)
;)/>/>
Jajnick #3
Posted 09 October 2012 - 02:07 PM
Why do I have to find out such things at such moments ._.