explanyation

for the full source see the dollcode-tools repo on codeberg

ive tried to explain it as simply as possible but this one is not great at explaining code

text > hex

text is processed character by character, using the String.codePointAt() function to get the decimal unicode representation. the decimal is then converted to binyary using String.toString(2) and assembled into bytes according to utf-8 encoding. each byte is then converted into hex with parseInt(byte, 2).toString(16) and either returned or converted into dollcode.

hex > text

going backwards is a matter of converting the hex to binyary (parseInt(octet, 16).toString(2)) and then extracting the meaningful bits. the bits are then assembled and converted into decimal which is used to generate a character. (String.fromCodePoint(parseInt(bin, 2)))

hex > dollcode

converting hex into dollcode first converts each hex octet into deciaml (parseInt(octet, 16)), and then takes the mod 3 of each place, and adds the respective nib

to be perfectly honest i'm not 100% on how this works but it does and i can replicate it on paper so 🤷‍♀️

dollcode > hex

converting the dollcode to hex again first requires converting to decimal. which requires reversing the incoming dollcode so we can iterate from the greatest to least place, mapping each nib to a 1, 2, or 3, then raising the value at the current index to the appropriate power of 3.

const decimal = numbers.reduce((acc, val, ind) => {
    // reduce based on value place
    const r = val * Math.pow(3, ind)
    const res = r + acc
    return res
}, 0)
this is the first time ive ever seen the reduce function so thats neat

then the decimal is converted to hex using Number.toString(16)

also as a matter of credit, the code, site layout, and css are heavily referenced from noe's original work