Converting numbers

Is there a way, in OpenAF, to convert a decimal number to hex? Or to binary? Or to octal? Yes, there is on the ow.format library.

Start by loading the library:

> ow.loadFormat();

Converting from hexadecimal to decimal:

> ow.format.fromHex("1F78")
8056

Converting from decimal to hexadecimal:

> ow.format.toHex(8056)
"1f78"

Converting from decimal to octal:

> ow.format.toOctal(8056)
"17570"

Converting from octal to decimal:

> ow.format.fromOctal(17570)
8056

Converting from decimal to binary:

> ow.format.toBinary(12345)
"11000000111001"

Converting from binary to decimal:

> ow.format.fromBinary("11000000111001")
12345

And that’s it. For conversions between arrays of bytes and the corresponding hexadecimal representation there are also functions like ow.format.string.toHex and ow.format.string.toHexArray.