# Binary by xiangpeng

VIEWS: 122 PAGES: 15

• pg 1
How Computers Represent
Numbers

Friday, Week 5
Binary Code
• A series of 1’s and 0’s
• Place value is in powers of 2
The Decimal System
• Analyze the number 2,473
• 2,473 = 2 * 1000 + 4 * 100 + 7 * 10 + 3 *1
• 2,473 = 2 * 10^3 + 4 * 10^2 + 7 * 10^1 + 3
* 10^0
• Each position in our number represents a
different power of 10
• Decimal is a base 10 system
Binary as Base 2
• 1011001 = 1*2^6 + 0*2^5 + 1*2^4 +
1*2^3 + 0*2^2 + 0*2^1 +1*2^0
• 1011001 = 1*64 + 0*32 + 1*16 + 1*8 +
0*4 + 0*2 + 1*1
• 1011001 = 64 + 16 + 8 + 1
• 1011001 = 89 (decimal)
Base 3
• 1011001 = 1*3^6 + 0*3^5 + 1*3^4 +
1*3^3 + 0*3^2 + 0*3^1 +1*3^0
• 1011001 = 1*729 + 0*243 + 1*81 + 1*27
+ 0*9 + 0*3 + 1*1
• 1011001 = 729 + 81 + 27 + 1
• 1011001 = 838 (decimal)
Exercise
•   Find the decimal equivalent of 100111
•   100111 = 1*2^5 + 1*2^2 + 1*2^1 + 1*2^0
•   100111 = 1*32 + 1*4 + 1*2 + 1*1
•   100111 = 32 + 4 + 2 + 1
•   100111 = 39 (decimal)
• Base-16 system
• Needs digits 0 through 15 - we don’t have
numbers for 10 - 15.
• We use the letters A - F to represent the
numbers 10 - 15.
Exercise
• What would 3B in hexadecimal be in
decimal?
• 3B = 3 * 16 ^ 1 + 11 * 16 ^ 0
• 3B = 3 * 16 + 11 * 1
• 3B = 48 + 11
• 3B = 59
• 4 binary digits equal one hexadecimal
number
• 0101 (binary) = 5 (hex)
• 1101 (binary) = D (hex)
• 1011101 (binary) = 93 (decimal) = 5D
(hex)
Decimal to Binary

• Divide by 2 and keep   39/2 =   19   Rem 1
track of the           19/2 =   9    Rem 1
remainders.
9/2 =    4    Rem 1
• 39 (decimal) =
100111 (binary)        4/2 =    2    Rem 0
2/2 =    1    Rem 0
1/2 =    0    Rem 1
Exercise
• Convert 89 (decimal) to binary
• 89 (decimal) = 1011001 (binary)
89/2 =   44   R1
44/2 =   22   R0
22/2 =   11   R0
11/2 =   5    R1
5/2 =    2    R1
2/2 =    1    R0
1/2 =    0    R1
Why use binary?
• Binary uses more digits than decimal, so
why do we use it?
• Electronic hardware can either be ‘on’ or
‘off’ - nothing in between.
• Binary fits this pattern - ‘on’ state is 1 in
binary and ‘off’ state is 0 in binary.
Numeric Representation of Letters and
Digits
• In a computer, letters and digits are
represented by numeric codes.
• Example Code:
A    B   C   D   E   F   G   H   I   J   K   L    M
1    2   3   4   5   6   7   8   9   10 11   12   13
N    O   P   Q   R   S   T   U   V   W X     Y    Z
14   15 16 17 18 19 20 21 22 23 24           25   26

• What does this say? 8 9 3 12 1 19 19
ASCII and Unicode

• ASCII (American Standard Code for Information
Interchange) - 7 bit code that represents
commony used English characters.
• Unicode - Newer 16 bit code that is able to
encode large asian alphabets. (ASCII is included
as a subset.)
72-101-108-108-111-32-67-108-97-115-115-33
Sp     !     “     #    \$    %    &    ‘    (    )    *    +    ,    -
32     33    34    35   36   37   38   39   40   41   42   43   44   45
.      /     0     1    2    3    4    5    6    7    8    9    :    ;
46     47    48    49   50   51   52   53   54   55   56   57   58   59
<      =     >     ?    @    A    B    C    D    E    F    G    H    I
60     61    62    63   64   65   66   67   68   69   70   71   72   73
J      K     L     M    N    O    P    Q    R    S    T    U    V    W
74     75    76    77   78   79   80   81   82   83   84   85   86   87
X      Y     Z     [    \    ]    ^    _    `    a    b    c    d    e
88     89    90    91   92   93   94   95   96   97   98   99   100 101
f      g     h     i    j    k    l    m    n    o    p    q    r    s
102    103   104   105 106   107 108   109 110 111 112 113      114 115
t      u     v     w    x    y    z    {    |    }    ~
116    117   118   119 120   121 121   123 124 125 126

To top