# Computational biology at CSU

## DSCI 512: RNA-seq

### Questions?

wiki:curtain_bin_vs_txt

This is an old revision of the document!

How is text binary? Well, programs that read text really read binary, but know to display it as text.

Let's say that I wanted to know what binary numbers represent the text “Hey Mom!” That representation is called a character encoding and we are using ASCII. From the table on that page, I know that 72, 101 and 121 respectively encode the letters “H”, “e”, “y”.

We can use python to verify that:

```\$ python -c 'print chr(72), chr(101), chr(121)'
H e y```

But how is this binary? Numbers like 72 are decimals, that is, they use a base 10 system. The base 2 representation (the binary string) can also be gotten with python, this time using string formatting.

```\$ python -c 'print "{0:b}".format(72)'
1001000```

To show you that it's all numbers, I used the hexdump command. It's hard to use, so don't worry about the parameters. Just know that it shows four numbers, followed by “=”, followed by the characters they encode.

```\$ echo -ne 'Hey Mom!' | hexdump -v -e '4/1 "%d " " =|"' -e '4/1 "%_p|" "\n"'
72 101 121 32 =|H|e|y| |
77 111 109 33 =|M|o|m|!|```

I can't find a utility to that shows you the binary string, because it's actually kind of useless. But you can show any number as its binary representation with python string formatting.

The capital letter 'H' holds the 72nd place in the ASCII character chart. Here is its binary string.

```\$ python -c 'print "{0:b}".format(72)'
1001000```

To go the other direction, i.e. show the ASCII character at a given index:

```\$ python -c 'print chr(72), chr(101), chr(121)'
H e y```
wiki/curtain_bin_vs_txt.1531550065.txt.gz · Last modified: 2018/07/14 00:34 by david