Binary Data Representation

Binary is a set of bits (8 bits making up one byte).
Each bit is stored as either a 0 or a 1.

The binary code is a base 2 system (humans usually use the base 10 system) and is constructed using the powers of 2 according to the following pattern. The numbers of bits, that can be used, determine how many different values you can encode. For a 1 byte (8 bit) system, these would be the values, for example:
Decimal number
128
64
32
16
8
4
2
1
Power of 2
27
26
25
24
23
22
21
20
Binary number
10000000
01000000
00100000
00010000
00001000
00000100
00000010
00000001

Therefore 00000000 would be 0 in decimal and 11111111 would be 255 in decimal. So with one byte one can store up to 256 different values.

Text storage
To store any data (including text) digitally, it has to be converted to binary. There are several encodings to do so for text, Unicode being currently used commonly, which originates from ASCII.

ASCII
On both Windows/DOS and Unix systems, the 128 most commonly-used characters are each represented by a sequence of 7 bits known as the character’s ASCII code. They are traditionally stored as bytes (8 bits), i.e. the 7-bit ASCII code plus a leading zero. The characters include letters, digits, punctuation marks, and nonprintable control characters such as the backspace, tab, carriage return, etc.

Unicode
Unicode is a further development of ASCII. Characters are now stored in 2 bytes (as oppose to 1 byte as in ASCII) and therefore more characters can be stored and displayed, allowing for an international character set. The first 128 characters of the ASCII and Unicode code are the same.


Images and binary
Images are also stored in a binary format. Each color is represented by a different binary code. Nowadays modern computers use a color depth of 32 bit; i.e.
232 colors can be displayed. The lower the color depth, the less bits are used and the less colors there are available.

Below a comparison of an image with different color depths:
Origional (28=256 colors)
24=16 colors
origional.png
4_bit_(16_farben).png
23=8 colors
22=4 colors
3_bit_(8_farben).png
2_bit_(4_farben).png
21=2 colors

1_bit_(2_farben).png


Written by Jocbe
Last update: 17. March 2011

Sources: