Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Binary to Binary: The Power Move

The most powerful use of binary comprehensions is transforming binaries into other binaries. Let’s invert all the bytes:

lfe> (binary-comp ((<<byte>> (binary-gen (<= #B(1 2 3 4 5)))))
                  (- 255 byte))
#B(254 253 252 251 250)

This inverts each byte by subtracting it from 255—a common operation in image processing (creating negatives) and certain encryption schemes (though please don’t use this for actual encryption; that way lies security disasters).