This preview shows page 1. Sign up to view the full content.
Unformatted text preview: EECS 270 Binary Numbers
John Hayes Winter 2008 So far we've been looking at binary signals, yet most concepts in the real world are represented as base10 (decimal) numbers. How can we represent these concepts on a computer? First let's fully understand our "normal" number system... We use a positional number system; one where a number is represented by a string of digits and each digit position has an associated weight
> Example 1: 836.24 = 8*100 + 3*10 + 6*1 + 2*.1 + 4*.01 = 8*102 + 3*101 + 6*100 + 2*101 + 4*102 10 is called the radix or base The "decimal point" is more generally referred to as the radix point Ordinary "decimal" numbers use base 10 But essentially any number can be used as base
> Example: Base 3 with digits {0, 1, 2}: 10213 = 1*33 + 0*32 + 2*31 + 1*30 = 3410 What is an example of a nonpositional number system? E D $14BCA19 637 $1423# % 1)(&$" 6 5 9 @ 5 8 6 5 # 0 # ' % # ! 5 1 86 3 6$55 1# 42 23 00 1# #)' (% &# #$! " 5 6 5 # 0 ' % ! 51 63 $1#423 1#)'(%&#$!" 199 9 88377 7 66$143## # %% % 1)(&$" 1 2 3 1 In general, for any radix r, the value of a number written can be expressed as the weighted sum:
p 1 i=n where di is a member of the set of digits for baser In general, the lower the base, the more digits are needed Some useful number bases: > 10 decimal (10 fingers!) > 2 binary (0/1 high/low voltage) > 8 octal and 16 hexadecimal (compact representation of binary) Binary (base2) use digits {0, 1} "Bit" = binary digit Example:
1011.1012 = 1*23 + 0*22 + 1*21 + 1*20 + 1*21 + 0*22 * 1*23 = 8 + 2 + 1 + .5 +.125 = 11.62510 2782510 = 1101100101100012 Large numbers require lots of bits! Because of this, it's often convenient to use octal or hexadecimal as a shorthand for binary Octal (base8) uses digits {0, 1, 2, 3, 4, 5, 6, 7} Example: Because 8 is a power of 2 (8 = 23), conversion from binary to octal and viceversa is easy! Each octal digit represents exactly 3 binary digits.
Octal to binary: Binary to octal: 6 2 18 = 3218 = 3*82 + 2*81 + 1*80 = 20910 001 011.110 12 = 2 = 100 1 % &# #$! " H % &7 7$ 8 & % ! % 8 22 2 &$" HGG G &$55 5 &FF F %&#$!" H %&7$ 8& 3 . 6 2 1$" 4&7 4B % # ! P 6 2 3# 42 223 F (% &# $! " 23#43 F(%&#$!" 23#423 F(%&#$!" 34377 77 (&$" 2 # F % # !
dp1dp... 0.d1d2... n d d di r i I
110 010 0012
Make sure to pad with 0's when necessary! 4 5 48 6 2 Hexadecimal (base16) uses digits {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F} Example: 8B716 = 8*162 + 11*161 + 7*160 = 223110 Because 16 = 24, each hexadecimal digit represents 4 binary digits Base conversion: > Hexadecimal to binary: A 816 = 1010 10002 > Binary to hexadecimal: 0110 11102 = 6 E16 Often hex numbers are denoted with the prefix "0x" instead of a subscript 16 (0x3B8 3B816) How to convert from hex to octal, or from octal to hex?? > Go through binary! Why use hex? 2782510 = 1101100101100012 = 6CB116 So far we know the following base conversions: Converting from baser to decimal is easy: Write the > binary, octal, hex decimal > binary octal hex given number using powers of r and sum the powers using ordinary decimal arithmetic. Converting from decimal to baser is harder. A general method is to use repeated division by the base r: % 1# $! " 4P &77 S 8 (B BB33D DD37 4R RR3# ) %% # ! 77 22 22 1$" 4&S (3##3343)QQ QQ %1#$!" 4P&S 8(B33D374R3#) 1#$!" 4&7S 8(3#3343#) PP 7 8 # # $1 8W %&4$1U#43 2$55 1 8 W % &## 4$55 1TT U# 423 5 8 % # V 5 9 T # 22$199 9 W22 2 &4VV$199U422377 7 FF F 2342 WB &4R X # 8 % #
7 8 9 3 5 8 % # V 5 9 T 5 19 W2 14$1d19 8i437 )h 6 B % 2 22gff% 19 eYY d5 1 8 ( 88 W 8 bbcDD3 6 3773# $0 1# )' HG $` a %% 9 YY 5 8 8 8 2g%19ed51 8( W 8c3 633#$01#)'HG$`a gff1ed199 99 (22 22 WVV VV bbcDD3## ## 3773$1)H$aYY YY g19ed51 8( 8W 8c3 633#$01#)'HG$a 6 # 0 # ' G `` Nr Divide by r: Divide again by r: Divide again by r: Divide again by r: Use repeated multiplication by base r Nr = (d3*r3 + d2*r2 + d1*r1 + d0r0)10 d3*r3 + d2*r2 + d1*r1 + d0r0 d3*r2 + d2*r1 + d1 remainder d0 d3*r1 + d2 remainder d1 d3 remainder d2 0 remainder d3 (remember that dx < r) 101.4510 = ?2, ?16 Watch for repeating digits... Sometimes conversion won't be exact... 12 11 10 4 # 8 % # 42 WB &4R X ...
View
Full
Document
This note was uploaded on 04/04/2008 for the course EECS 270 taught by Professor Hayes during the Winter '08 term at University of Michigan.
 Winter '08
 Hayes

Click to edit the document details