Data Representation
All data on digital computers is represented as a sequence of 0s and 1s. This includes numeric data, text, executable files, images, audio, and video. The ASCII standard associates a seven bit binary number with each of 128 distinct characters. The MP3 file format rigidly specifies how to encode each raw audio file as a sequence of 0s and 1s. All data are numbers, and all numbers are data.
In this section we describe how to represent integers in binary, decimal, and hexadecimal and how to convert between different representations. We also describe how to represent negative integers.
Number systems.
There are many ways to represent integers: the number of days in the month of October can be represented as 31 in decimal, 11111 in binary, 1F in hexadecimal, or XXXI in Roman Numerals. It is important to remember than an integer is an integer, no matter whether it is represented in decimal or with Roman Numerals.
Binary Number
In mathematics and computer science, the binary numeral system, or base-2 numeral system, represents numeric values using two symbols: 0 and 1. More specifically, the usual base-2 system is a positional notation with a radix of 2. Numbers represented in this system are commonly called binary numbers
Computers are based on the binary (base 2) number system because each wire can be in one of two states (on or off)
Examples:
10101_{2} = 10101B = 1×2^{4}+0×2^{3}+1×2^{2}+0×2^{1}+1×2^{0}^{ }= 16+4+1= 21
10111_{2} = 10111B = 1×2^{4}+0×2^{3}+1×2^{2}+1×2^{1}+1×2^{0}^{ }= 16+4+2+1= 23
100011_{2} = 100011B = 1×2^{5}+0×2^{4}+0×2^{3}+0×2^{2}+1×2^{1}+1×2^{0}^{ }=32+2+1= 35
decimal
We are most familiar with performing arithmetic with the decimal (base 10) number system. This number system has been widely adopted, in large part because we have 10 fingers. However, other number systems still persist in modern society.
decimal number system, also called Hindu-Arabic, or Arabic, number system, in mathematics, positional numeral system employing 10 as the base and requiring 10 different numerals, the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. It also requires a dot (decimal point) to represent decimal fractions. In this scheme, the numerals used in denoting a number take different place values depending upon position. In a base-10 system the number 543.21 represents the sum (5 × 10^{2}) + (4 × 10^{1}) + (3 × 10^{0}) + (2 × 10^{−1}) + (1 × 10^{−2}).
Decimal numbers uses digits from 0..9.
These are the regular numbers that we use.
Example:
2538_{10} = 2×10^{3}+5×10^{2}+3×10^{1}+8×10^{0}
Octal
Octal (pronounced AHK-tuhl , from Latin octo or “eight”) is a term that describes a base-8 number system. An octal number system consists of eight single-digit numbers: 0, 1, 2, 3, 4, 5, 6, and 7. The number after 7 is 10. The number after 17 is 20 and so forth.
The octal numeral system, or oct for short, is the base-8 number system, and uses the digits 0 to 7. Octal numerals can be made from binary numerals by grouping consecutive binary digits into groups of three (starting from the right). For example, the binary representation for decimal 74 is 1001010, which can be grouped into (00)1 001 010 – so the octal representation is 112.
In the decimal system each decimal place is a power of ten. For example:
In the octal system each place is a power of eight. For example:
By performing the calculation above in the familiar decimal system we see why 112 in octal is equal to 64+8+2 = 74 in decimal.
Examples:
27_{8} = 2×8^{1}+7×8^{0}^{ }= 16+7 = 23
30_{8} = 3×8^{1}+0×8^{0}^{ }= 24
4307_{8} = 4×8^{3}+3×8^{2}+0×8^{1}+7×8^{0}^{ }= 2247
Hexadecimal
In mathematics and computer science, hexadecimal (also base 16, or hex) is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0–9 to represent values zero to nine, and A, B, C, D, E, F (or alternatively a–f) to represent values ten to fifteen. For example, the hexadecimal number 2AF3 is equal, in decimal, to (2 × 16^{3}) + (10 × 16^{2}) + (15 × 16^{1}) + (3 × 16^{0}), or 10995.
Each hexadecimal digit represents four binary digits (bits), and the primary use of hexadecimal notation is a human-friendly representation of binary-coded values in computing and digital electronics. One hexadecimal digit represents a nibble, which is half of an octet or byte (8 bits)
Hex numbers uses digits from 0..9 and A..F.
H denotes hex prefix.
Examples:
28_{16} = 28H = 2×16^{1}+8×16^{0 }= 40
2F_{16} = 2FH = 2×16^{1}+15×16^{0 }= 47
BC12_{16} = BC12H = 11×16^{3}+12×16^{2}+1×16^{1}+2×16^{0 }= 48146
Decimal Base-10 |
Binary Base-2 |
Octal Base-8 |
Hexadecimal Base-16 |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
1 |
2 |
10 |
2 |
2 |
3 |
11 |
3 |
3 |
4 |
100 |
4 |
4 |
5 |
101 |
5 |
5 |
6 |
110 |
6 |
6 |
7 |
111 |
7 |
7 |
8 |
1000 |
10 |
8 |
9 |
1001 |
11 |
9 |
10 |
1010 |
12 |
A |
11 |
1011 |
13 |
B |
12 |
1100 |
14 |
C |
13 |
1101 |
15 |
D |
14 |
1110 |
16 |
E |
15 |
1111 |
17 |
F |
16 |
10000 |
20 |
10 |
17 |
10001 |
21 |
11 |
18 |
10010 |
22 |
12 |
19 |
10011 |
23 |
13 |
20 |
10100 |
24 |
14 |
21 |
10101 |
25 |
15 |
22 |
10110 |
26 |
16 |
23 |
10111 |
27 |
17 |
24 |
11000 |
30 |
18 |
25 |
11001 |
31 |
19 |
26 |
11010 |
32 |
1A |
27 |
11011 |
33 |
1B |
28 |
11100 |
34 |
1C |
29 |
11101 |
35 |
1D |
30 |
11110 |
36 |
1E |
31 |
11111 |
37 |
1F |
32 |
100000 |
40 |
20 |
Reference
http://www.willamette.edu/~gorr/classes/cs130/lectures/data_rep.htm
http://introcs.cs.princeton.edu/java/51data/
http://en.wikipedia.org/wiki/External_Data_Representation
http://guide.dhcuration.org/representation/