Professional Documents
Culture Documents
Binary and Decimal Numbers
Binary and Decimal Numbers
Prof. Rosenthal
Another name for decimal numbers are base-10 (pronounced "base ten") numbers.
Decimal Equivalent 1 2 3 87
When you see a number that consists of only ones and zeroes, you must be told if it is a binary number or a decimal number.
(Well see later how text and pictures can be converted into simple numbers for now just take our word for it.)
Therefore, if we can derive a way to store and retrieve numbers electronically this method can be used by computers to store and retieve any type of information.
Binary Numbers are at the heart of how a computer stores all information
Computers Store ALL information using Binary Numbers
11
Computers use binary numbers in different ways to store different types of information.
Common types of information that are stored by computers are :
Whole numbers (i.e. Integers). Examples: 8 97 -732 0
-5 etc
Numbers with decimal points. Examples: 3.5 -1.234 0.765 999.001 etc
Keep reading
12
Integers
Integers (e.g. 87) A computer stores integer numbers (i.e. whole numbers) simply as the equivalent binary value for that number.
13
14
15
Some ASCII values (values 1-31 and 128 are not shown)
32 = Space 33 = ! 34 = 35 = # 36 = $ 37 = % 38 = & 39 = ` 40 = ( 41 = ) 42 = * 43 = + 44 = , 45 = 46 = . 47 = / 48 = 0 49 = 1 50 = 2 51 = 3 52 = 4 53 = 5 54 = 6 55 = 7 56 = 8 57 = 9 58 = : 59 = ; 60 = < 61 = = 62 = > 63 = ? 64 = @ 65 = A 66 = B 67 = C 68 = D 69 = E 70 = F 71 = G 72 = H 73 = I 74 = J 75 = K 76 = L 77 = M 78 = N 79 = O 80 = P 81 = Q 82 = R 83 = S 84 = T 85 = U 86 = V 87 = W 88 = X 89 = Y 90 = Z 91 = [ 92 = \ 93 = ] 94 = ^ 95 = _ 96 = ` 97 = a 98 = b 99 = c 100 = d 101 = e 102 = f 103 = g 104 = h 105 = i 106 = j 107 = k 108 = l 109 = m 110 = n 111 = o 112 = p 113 = q 114 = r 115 = s 116 = t 117 = u 118 = v 119 = w 120 = x 121 = y 122 = z 123 = { 124 = | 125 = } 126 = ~
16
17
EBCDIC
Is a different numbering system used by IBM Mainframe computers. It is very similar to ASCII but uses different numbers to represent the symbols. EBCDIC stands for Extended Binary Coded Decimal Interchange Code
Unicode
ASCII and EBCDIC are limited to just the basic English letters and common symbols. Today computers use many different symbols including letters from languages that dont use English letters (e.g. Hebrew, Chinese, etc.) and international symbols (e.g. the English pound sign) Unicode defines a unique number for every symbol in all known languages (e.g. Hebrew, Chinese, etc.) and commonly used non-letter symbols (e.g. English pound sign, copyright symbol, etc). Modern programs are moving towards using Unicode to store letters and symbols. It should be noted that Unicode numbers 1-128 correspond to the EXACT SAME symbols as ASCII 1-128
19
1X1
1X4 0X2
=1 =0 =4 ---5
20
21
Example
The value of binary 01100001 is decimal 105. This is worked out below: 128 64 32 16 8 4 2 1 ----------------------------------------------------------------------
0
0X4
0
0X2
1
1X1 =1 =0 =0 =8 =0 = 32 = 64 =0 ---Answer: 105
1X8 0 X 16 1 X 32 1 X 64 0 X 128
22
Another example
The value of binary 10011100 is decimal 156. This is worked out below: 128 64 32 16 8 4 2 1 ----------------------------------------------------------------------
1
1X4
0
0X2
0
0X1 =0 =0 =4 =8 = 16 =0 =0 = 128 ---Answer: 156
1X8 1 X 16 0 X 32 0 X 64 1 X 128
23
Some Terminology
The following are some terms that are used in the computer field
Each digit of a binary number is called a bit. A binary number with eight bits (i.e. digits) is called a byte.
24
25
26
# of bits 1 bit: 2 bits: 3 bits: 4 bits: 5 bits: 6 bits: 7 bits: 8 bits: 9 bits: 10 bits: etc.
27
28
29
General rule: for a binary number with n bits, the largest possible value is : 2n - 1
30
Largest numbers
The following are the largest values for binary numbers with a specific number of bits:
# of bits 1 bit: 2 bits: 3 bits: 4 bits: 5 bits: 6 bits: 7 bits: 8 bits: etc. largest binary # 1 11 111 1111 11111 111111 1111111 11111111 decimal value 1 3 7 15 31 63 127 255
31
Example 2: To convert the decimal number 106 to binary, you will need at least 7 bits. (With 6 bits you can only store numbers up to 63 but with 7 bits you can store numbers up to 127)
32
64 32 16 8 4 2 1 --------------------------------------------------------------------------------
33
34
35
Example
Example: convert decimal 106 to binary
Step 1: You need 7 bits (see earlier slides for explination). Step 2: keep track of position values for bits
64 32 16 8 4 2 1 --------------------------------------------------------------------------------
64 32 16 8 4 2 1 --------------------------------------------------------------------------------
subtract : 106 - 64 = 42
36
Example (continued-2)
Step 4: Check next position value (i.e. 32)
32 is less than 42, therefore the next binary digit is 1
64 32 16 8 4 2 1 -------------------------------------------------------------------------------
subtract : 42 - 32 = 10
37
Example (continued-3)
Step 4(continued): Check next position value (i.e. 8)
8 is less than 10, therefore the next binary digit is 1
64 32 16 8 4 2 1 -------------------------------------------------------------------------------
subtract : 10 - 8 = 2
38
Example (continued-4)
Step 4(continued): Check next position value (i.e. 2)
2 is equal to 2, therefore the next binary digit is 1
64 32 16 8 4 2 1 -------------------------------------------------------------------------------
Since the position value was equal to the number (i.e. 2) the rest of the binary digits are all zeros
64 32 16 8 4 2 1 ---------------------------------------------------------------------------
Answer:
1101010
39
41
42
Hexadecimal numbers
The following are all valid hexadecimal nubmers
A 9 1001 9C5 BFE Etc.
(yes, a hexadecimal number does not HAVE TO contain letters) (yes, a hexadecimal number does not HAVE TO contain letters)
To understand what a specific hexadecimal number means, you can convert it into an equivalent decimal number. (see next slide)
43
1
1 X 256
2
2 X 16
F
15 X 1 = 15 = 32 = 256 = 40,960 ---Answer: 41,263
10 X 4096
44
45
46
47
49
50
BYTE
definition: 8 bits
NYBLE
definition: 4 bits
51
Prefixes
Prefixes
Kilo: one thousand Mega: one millioin Giga: one billion Tera: one trillion Peta: one quadrillion Exa: one quintillion etc.
52
Data sizes
Data sizes
Kilobyte (KB)
"about" one thousand bytes exactly 210 or 1024 bytes
Megabyte (MB)
"about" one million bytes exactly 220 or 1,048,576 bytes
Gigabyte (GB)
"about" one billion bytes exactly 230 or 1,073,741,824 bytes
Terabyte (TB)
"about" one trillion bytes exactly 240 or 1,099,511,627,776 bytes
53
54
Speeds
MBPS = one MegaByte per second MbPS = one Mega Bit per second
55
56
57
CPU
58
59
61
A-F
a is 10 b is 11 c is 12 d is 13 e is 14 f is 15
62
63
64
Applications
HTML : color codes Shorthand for binary
See hex editor