display | more...
01001111 01110101 01110010 00100000 01100110 01100001 01110100
01101000 01100101 01110010 00101100 00100000 00001010 01110111
01101000 01101111 00100000 01100001 01110010 01110100 00100000
01101001 01101110 00100000 01101000 01100101 01100001 01110110
01100101 01101110 00101100 00100000 00001010 01101000 01100001
01101100 01101100 01101111 01110111 01100101 01100100 00100000
01100010 01111001 00100000 01010100 01101000 01111001 00100000
01101110 01100001 01101101 01100101 00101110 00100000 00001010
01010100 01101000 01111001 00100000 01101011 01101001 01101110
01100111 01100100 01101111 01101101 00100000 01100011 01101111
01101101 01100101 00101100 00100000 00001010 01110100 01101000
01111001 00100000 01110111 01101001 01101100 01101100 00100000
01100010 01100101 00100000 01100100 01101111 01101110 01100101
00100000 00001010 01101111 01101110 00100000 01100101 01100001
01110010 01110100 01101000 00100000 01100001 01110011 00100000
01101001 01110100 00100000 01101001 01110011 00100000 01101001
01101110 00100000 01101000 01100101 01100001 01110110 01100101
01101110 00101110 00100000 00001010 01000111 01101001 01110110
01100101 00100000 01110101 01110011 00100000 01110100 01101000
01101001 01110011 00100000 01100100 01100001 01111001 00100000
01101111 01110101 01110010 00100000 01100100 01100001 01101001
01101100 01111001 00100000 01100010 01110010 01100101 01100001
01100100 00101100 00100000 00001010 01100001 01101110 01100100
00100000 01100110 01101111 01110010 01100111 01101001 01110110
01100101 00100000 01110101 01110011 00100000 01101111 01110101
01110010 00100000 01110100 01110010 01100101 01110011 01110000
01100001 01110011 01110011 01100101 01110011 00101100 00100000
00001010 01100001 01110011 00100000 01110111 01100101 00100000
01100110 01101111 01110010 01100111 01101001 01110110 01100101
00100000 01110100 01101000 01101111 01110011 01100101 00100000
01110111 01101000 01101111 00100000 01110100 01110010 01100101
01110011 01110000 01100001 01110011 01110011 00100000 01100001
01100111 01100001 01101001 01101110 01110011 01110100 00100000
01110101 01110011 00101110 00100000 00001010 01001100 01100101
01100001 01100100 00100000 01110101 01110011 00100000 01101110
01101111 01110100 00100000 01101001 01101110 01110100 01101111
00100000 01110100 01100101 01101101 01110000 01110100 01100001
01110100 01101001 01101111 01101110 00101100 00100000 00001010
01100010 01110101 01110100 00100000 01100100 01100101 01101100
01101001 01110110 01100101 01110010 00100000 01110101 01110011
00100000 01100110 01110010 01101111 01101101 00100000 01100101
01110110 01101001 01101100 00101110 00100000 00001010 01000110
01101111 01110010 00100000 01110100 01101000 01101001 01101110
01100101 00100000 01101001 01110011 00100000 01110100 01101000
01100101 00100000 01101011 01101001 01101110 01100111 01100100
01101111 01101101 00101100 00100000 00001010 01100001 01101110
01100100 00100000 01110100 01101000 01100101 00100000 01110000
01101111 01110111 01100101 01110010 00101100 00100000 01100001
01101110 01100100 00100000 01110100 01101000 01100101 00100000
01100111 01101100 01101111 01110010 01111001 00100000 00001010
01100110 01101111 01110010 00100000 01100101 01110110 01100101
01110010 00100000 01100001 01101110 01100100 00100000 01100101
01110110 01100101 01110010 00101110 00001010 01000001 01101101
01100101 01101110 00101110 00100000 

In order to make this conversion, I wrote a little scheme program. This is my first and only attempt at using scheme. It's beautiful, mathematically, but I haven't quite got the hang of it. This should work on any unix system running guile.

":"; exec guile -s $0 "$@"

(define s "Our father,
who art in heaven,
hallowed by Thy name.
Thy kingdom come,
thy will be done
on earth as it is in heaven.
Give us this day our daily bread,
and forgive us our trespasses,
as we forgive those who trespass against us.
Lead us not into temptation,
but deliver us from evil.
For thine is the kingdom,
and the power, and the glory
for ever and ever.
Amen. ")

(define num->bin-rec
  (lambda (n count)
    (if (= count 1)
      (number->string (modulo n 2))
      (string-append 
        (num->bin-rec (quotient n 2) (- count 1))
        (number->string (modulo n 2))))))

;; Convert a number into a string of 1's and 0's.
;; Number between 0 and 255.
(define num->bin
  (lambda (n) (num->bin-rec n 8)))

;; Converts a char to binary string
(define char->bin 
  (lambda (c) (num->bin (char->integer c))))

;; Converts a string into a list of strings, each a binary
;; representation of a character from the string.
(define string->bin 
  (lambda (st) (map char->bin (string->list st))))

(display (string->bin s))

This essentialy takes the idea of the Lord's Prayer and encodes it into English sentences. These English sentences are written down using the latin alphabet. Each letter is represented on a computer as a number, as defined by ASCII. Each number is converted into a string of 1's and 0's that are the binary representation of that number.

It would be neat if a knight of the lambda calculus would show me how to make that function tail-recursive.


Any says re The Lord's Prayer : binary: The easy way to make it tail-recursive would be to pass the string so far as an argument to num->bin-rec, putting the string-append inside the recursive call. Is that enough? Given more space I could write it out.

Perl version:

#!/usr/bin/perl
my $s="Our father,
who art in heaven,
hallowed by Thy name.
Thy kingdom come,
thy will be done
on earth as it is in heaven.
Give us this day our daily bread,
and forgive us our trespasses,
as we forgive those who trespass against us.
Lead us not into temptation,
but deliver us from evil.
For thine is the kingdom,
and the power, and the glory
for ever and ever.
Amen. \n";
print unpack('B*',$s), "\n";

Here's a C program that converts stdin to binary on stdout. One must simply pipe the Lord's Prayer into it.

#include <stdio.h>
int main(void) {
        char c;
        int i;
        while (fread(&c, sizeof(c), 1, stdin) == 1) {
                for (i = 7; i > -1; i--) {
                        printf("%d", (c & (1 << i)) >> i);
                }
                printf(" ");
        }
        printf("\n");
        return 0;
}

"The Lord's Prayer: binary" E2 Writeup, Copyright 2002-2007 Frank Grimes.

This writeup is released under the Creative Commons Attribution-ShareAlike License v2.5. (For details, see http://creativecommons.org/licenses/by-sa/2.5/ ) Alternatively, permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2. (For details, see http://www.gnu.org/licenses/fdl.html)

--Frank Grimes, 2007

Simple binary encoding in Python

Rationale

  • Use 64 characters (the 26 letters of the Latin alphabet in both lower and uppercase, the 10 digits, period and space)
  • Turn that character to a number
  • Represent that number in binary, padded to 8 bits for future use

Further work

  • A binary-to-string encoder
  • One byte allows for 256 different values, so this naive implementation only uses 1/4 of the potential space
  • Encoding to binary is easy because that’s how numbers are actually processed by the computer, but there are potentially infinite encodings (encoding to emoji, base65536, you name it.

The actual code

Somewhat readable, I hope

def char2bin(letter):
    '''Returns a naive, non-standard binary encoding of a single character. '''
    aleph = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789. '
    if letter in aleph:
        result = format(aleph.index(letter), '08b') + ' '
    else:
        result = format(64, '08b') + ' '  # return 01000000 if character is not in the alphabet
    return result
#%
def str2bin(string, row=5):
    '''Returns a naive binary encoding of string.'''
    binaried = ''
    for letter in string:
        binaried += char2bin(letter)
    formatted = ''
    for idx, bit in enumerate(binaried):
        if idx % ((9 * row)) == 0 and idx > 0:
            formatted += '\n'
        formatted += bit
    return formatted
lord = '''
Our Father, which art in heaven,
Hallowed be thy name.
Thy kingdom come, thy will be done in earth as it is in heaven.
Give us this day our daily bread.
And forgive us our debts, as we forgive our debtors.
And lead us not into temptation, but deliver us from evil.
For thine is the kingdom, and the power, and the glory for ever.
Amen. 
'''
print(str2bin(lord))
01000000 00101000 00010100 00010001 00111111 
00011111 00000000 00010011 00000111 00000100 
00010001 01000000 00111111 00010110 00000111 
00001000 00000010 00000111 00111111 00000000 
00010001 00010011 00111111 00001000 00001101 
00111111 00000111 00000100 00000000 00010101 
00000100 00001101 01000000 01000000 00100001 
00000000 00001011 00001011 00001110 00010110 
00000100 00000011 00111111 00000001 00000100 
00111111 00010011 00000111 00011000 00111111 
00001101 00000000 00001100 00000100 00111110 
01000000 00101101 00000111 00011000 00111111 
00001010 00001000 00001101 00000110 00000011 
00001110 00001100 00111111 00000010 00001110 
00001100 00000100 01000000 00111111 00010011 
00000111 00011000 00111111 00010110 00001000 
00001011 00001011 00111111 00000001 00000100 
00111111 00000011 00001110 00001101 00000100 
00111111 00001000 00001101 00111111 00000100 
00000000 00010001 00010011 00000111 00111111 
00000000 00010010 00111111 00001000 00010011 
00111111 00001000 00010010 00111111 00001000 
00001101 00111111 00000111 00000100 00000000 
00010101 00000100 00001101 00111110 01000000 
00100000 00001000 00010101 00000100 00111111 
00010100 00010010 00111111 00010011 00000111 
00001000 00010010 00111111 00000011 00000000 
00011000 00111111 00001110 00010100 00010001 
00111111 00000011 00000000 00001000 00001011 
00011000 00111111 00000001 00010001 00000100 
00000000 00000011 00111110 01000000 00011010 
00001101 00000011 00111111 00000101 00001110 
00010001 00000110 00001000 00010101 00000100 
00111111 00010100 00010010 00111111 00001110 
00010100 00010001 00111111 00000011 00000100 
00000001 00010011 00010010 01000000 00111111 
00000000 00010010 00111111 00010110 00000100 
00111111 00000101 00001110 00010001 00000110 
00001000 00010101 00000100 00111111 00001110 
00010100 00010001 00111111 00000011 00000100 
00000001 00010011 00001110 00010001 00010010 
00111110 01000000 00011010 00001101 00000011 
00111111 00001011 00000100 00000000 00000011 
00111111 00010100 00010010 00111111 00001101 
00001110 00010011 00111111 00001000 00001101 
00010011 00001110 00111111 00010011 00000100 
00001100 00001111 00010011 00000000 00010011 
00001000 00001110 00001101 01000000 00111111 
00000001 00010100 00010011 00111111 00000011 
00000100 00001011 00001000 00010101 00000100 
00010001 00111111 00010100 00010010 00111111 
00000101 00010001 00001110 00001100 00111111 
00000100 00010101 00001000 00001011 00111110 
01000000 00011111 00001110 00010001 00111111 
00010011 00000111 00001000 00001101 00000100 
00111111 00001000 00010010 00111111 00010011 
00000111 00000100 00111111 00001010 00001000 
00001101 00000110 00000011 00001110 00001100 
01000000 00111111 00000000 00001101 00000011 
00111111 00010011 00000111 00000100 00111111 
00001111 00001110 00010110 00000100 00010001 
01000000 00111111 00000000 00001101 00000011 
00111111 00010011 00000111 00000100 00111111 
00000110 00001011 00001110 00010001 00011000 
00111111 00000101 00001110 00010001 00111111 
00000100 00010101 00000100 00010001 00111110 
01000000 00011010 00001100 00000100 00001101 
00111110 00111111 01000000 

Log in or register to write something here or to contact authors.