W01-02B_Numbers - There are 10 types of people in the world...

This preview shows page 1 - 13 out of 50 pages.

1 02B Numbers Systems CSC 230 Department of Computer Science University of Victoria There are 10 types of people in the world; Those who understand binary and those who don’t. M&H: 2.1; 2.3; 2.4; 3.1.1; 3.1.2; Stl: Chapter 9; 10.1; 10.2; 10.3 (no multiplication/division)
2 Integer Number Systems Decimal Base: 10 Digits: 0,1,2,3,4,5,6,7,8,9 Binary Octal Base: 2 Base: 8 Digits: 0,1 Digits: 0,1,2,3,4,5,6,7 Hexadecimal Base: 16 Digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
3 Small Trivial Example 7423 in decimal = 3 + 20 + 400 + 7000 = 3 x 1 + 2 x 10 + 4 x 100 + 7 x 1000 3 x 10 0 + 2 x 10 1 + 4 x 10 2 + 7 x 10 3
4 Integer Number Systems: Base 10 - Decimal n 1 n 2 1 0 Integer D D D D n 1 n 1 D 10 Positional Number Systems e.g. 7423 in decimal Base 10: 1 0 2 10 3 10 0 0 D 10 n 2 n 2 D 10 1 1 D 10 3 10 7423 7 10 2 4 10
5 Integer Number Systems: Base 16 - Hexadecimal n 1 n 2 1 0 Integer D D D D n 1 n 2 1 0 n 1 n 2 1 0 D 16 D 16 D 16 D 16 Positional Number Systems e.g. 8254 in hexadecimal Base 16: 3 2 1 0 16 8254 8 16 2 16 5 16 4 16 NOTE: we have converted from hex to decimal! 10 8 4096 2 256 5 16 4 1 33,364
6 Integer Number Systems: Base 2 - Binary n 1 n 2 1 0 Integer D D D D n 1 n 2 1 0 n 1 n 2 1 0 D 2 D 2 D 2 D 2 Positional Number Systems e.g. 011011 in binary Base 2: 10 0 32 1 16 1 8 0 4 1 2 1 1 27 0 110 11 2 5 4 3 2 1 0 0 2 1 2 1 2 0 2 1 2 1 2 NOTE: we have converted from binary to decimal!
7 Weighted Positional Representation BASE: defines the range of values for digits (e.g. 0 9 for decimal; 0,1 for binary) GENERAL FORM AS AN n-BIT VECTOR: n i i i Integer Decimal Value d B 1 0 B = BASE d = DIGIT n i i i m Decimal Value d B  1 . 2 1 0 1 2 10 145 52 1 10 4 10 5 10 5 10 2 10 . . 100 40 5 0 5 0 02 Full example: Include fractions i = position
8 Memorize This Table! Binary Decimal Hexadecimal 0000 0 0 0001 1 1 0010 2 2 0011 3 3 0100 4 4 0101 5 5 0110 6 6 0111 7 7 1000 8 8 1001 9 9 1010 10 A 1011 11 B 1100 12 C 1101 13 D 1110 14 E 1111 15 F
9 Summary 1: Conversion from any Base “B” to Decimal Use the polynomial expansion in Base “B” as shown Base “B” gives the powers of the positional system 0 1 2 3 16 10 7423 3 16 2 16 4 16 7 16 3 1 2 16 4 256 7 4096 29,731 0 1 2 3 2 4 5 6 7 10 11001011 1 2 1 2 0 2 1 2 0 2 0 2 1 2 1 2 203
10 Conversion from One Base to Another Decimal to Base “B” for positive integers 1. Repeated division by base “B” 2. Collect remainders 3. Form result from right to left 35 10 = ??? 2 35/2 = 17 + remainder 1 17/2 = 8 + remainder 1 8/2 = 4 + remainder 0 4/2 = 2 + remainder 0 2/2 = 1 + remainder 0 1/2 = 0 + remainder 1 answer: 100011 2 Example 1: from decimal to binary
11 Conversion from One Base to Another Decimal to Base “B” for positive integers 1. Repeated division by base “B” 2. Collect remainders 3. Form result from right to left Example 2: from decimal to hexadecimal 35 10 = ??? 16 35/16 = 2 + remainder 3 2/16 = 0 + remainder 2 answer: 23 16
12 ( 6 7 ) 16 Conversion amongst binary, octal and hexadecimal is straightforward since 8 = 2 3 it takes 3 bits to represent the 8 octal digits 0 .. 7 Since 16 = 2 4 it takes 4

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture