Dense Binary Text Encoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dense Binary Text Encoding | |
// Encode each of the 26 letter as 1 to 26, in binary. | |
// Encode spaces as 0. | |
const ASCII_A = 65; | |
const ENCODED_SPACE = 0; | |
function dbte(str) { | |
const digits = str.toUpperCase().split(''); | |
const encoding = digits.reduce((obj, d, i) => { | |
obj.push(d === ' ' ? ENCODED_SPACE : d.charCodeAt(0) - ASCII_A); | |
return obj; | |
}, []); | |
return encoding.map(d => { | |
const bin = d.toString(2); | |
return '0'.repeat(5 - bin.length) + bin; | |
}); | |
} | |
const encoded = dbte('fidelity to purpose').join(' '); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment