ELE 107-Week 2: Number Systems & Binary Codes

Number Systems
• We use numbers in daily life as a quantization
tool. A numeral is an expression (symbol) that
represents a number.
• Numbers are abstractions that in turn represent
quantity: count, length, money, mass, duration
of time, etc.
• Unfortunately, numbers can be represented in
many different ways. Also, a number may have
extra information associated with it, which
increases the choice of ways to represent it.

Number Systems
ELE 107
Computers and Programming I

ELE 107 Dr. Derya Altunay

1

Number Systems

• As another example, consider the representation
of the number 11, which has no associated units.
Some different ways of representing 11 might be:
11 , XI , eleven , 11.00 ,
• The choices depend on the context. The two
representations 11 and 11.00 tell us that there are
also different types of numbers: whole numbers
and fractions.

– It clearly refers to a number. It involves a numeric
measure of quantity, and requires some choice of
units.
– So, we might say the fuel capacity is: 88,828
gallons, or 336,250 liters, or 606,701 pounds.

• Each representation describes the same amount
of fuel capacity, but because different units are
used, different numbers become involved.
3

Number Systems

ELE 107 Dr. Derya Altunay

4

Number Systems
• In Roman number system a symbol always
represents the same weight:

• Number systems may be symbolic,
– such as the Roman number system, or
– they may be weighted-positional, such as the Arabic
number system we normally use.

I = 1 , V = 5 , X = 10 , L = 50 , C = 100
D = 500 , M = 1000.

• If a symbol is repeated or lies to the right of
another symbol, then the value of the symbol is
additive. (CXV is …..).
• If a symbol is repeated or lies to the left of a
higher-valued symbol, then the value of the
symbol is subtractive. (XXC is …..).

• Modern number systems are weighted-positional
number systems.

ELE 107 Dr. Derya Altunay

2

Number Systems

• As an example, consider the description “the
fuel capacity of an Airbus A380”.

ELE 107 Dr. Derya Altunay

ELE 107 Dr. Derya Altunay

5

ELE 107 Dr. Derya Altunay

6

1

an integer. Derya Altunay Number Systems (734)14 4×142 + 3×141 + 7×140 7×142 + 3×141 + 4×140 4×196 + 3×14 + 7×1 78410 + 4210 + 710 7×196 + 3×14 + 4×1 137210 + 4210 + 410 (833)10 7×102 + 3×101 + 4×100 7×100 + 3×10 + 4×1 700 + 30 + 4 437 734 8 ELE 107 Dr. Derya Altunay (N)r = xn xn-1 xn-2 · · · x1 x0 . • Any number greater than r can be described by a combination these digits. Derya Altunay 4×102 + 3×101 + 7×100 4×100 + 3×10 + 7×1 400 + 30 + 7 • A weighted-positional number system can be constructed around any integral base. 2 . x-1 x-2 · · · x-m 9 Number Systems ELE 107 Dr. 7 ELE 107 Dr. … . Derya Altunay 12 2 . Derya Altunay 10 Number Systems General form: Position: n n-1 · · · 2 1 0 . -1 -2 · · · -m Position value: r n r n-1 · · · r2 r1 r0 . 1. prime. negative. • Number is a concept independent of its representation. • A number in any weighted-positional number system can be represented using a string of digits (symbols) : (1418)10 ELE 107 Dr. r -1 r -2 · · ·r -m Number: xn xn-1 · · · x2 x1x0 . ELE 107 Dr. Derya Altunay 734 Number Systems If the numbers are given in a different basis: (437)14 437 • There are r digits (symbols) in a base-r number system: { 0. radix 8. transcendental. x-1 x-2 · · · x-m integer part radix fractional part point where. r is the base of the number N. • Each digit has a value relative to its position in the number. r-1 } • The position values (weights) are powers of the base. 11 ELE 107 Dr. radix 2. any given number can be zero. the value of a particular digit depends on its position in the sequence of digits relative to a radix (base) point. xn is the most significant digit (MSD). radix 16. irrational.ELE 107-Week 2: Number Systems & Binary Codes Number Systems Number Systems • In a weighted-positional number system. x-m is the least significant digit (LSD). or complex depending on the underlying base system. Most common ones used are: radix 10. x-1 x-2 · · · x-m (N)r = xn xn-1 xn-2 · · · x1 x0 . fractional.

– Counting: » When you run out of digits.35 in the decimal system.ELE 107-Week 2: Number Systems & Binary Codes Number Systems Representation of Numbers – Each number has a unique representation. Derya Altunay 0 20 1 -1 -2 2 -1 2 -2 0 1 16 ELE 107 Dr. – Counting: ELE 107 Dr. (Each is called a bit for binary digit) • The weights of each position are powers of two.01)2 will be expanded as: 2 22 1 -1 -2 10 -1 10 -2 3 5 15 ELE 107 Dr. x-1 x-2 · · · x-m = xn r n +· · ·+x1r1 +x0r0 +x-1 r -1 +· · ·x-m r -m = (M)10 13 ELE 107 Dr.35 )10 will be expanded as: 0 100 2 » When you run out of digits. = (6 x 102) + (4 x 101) + (2 x 100) + (3 x 10-1) + (5 x 10-2) = 642. 6. 5. and 9. • A number such as (642.25 in the decimal system. • The positional values (weights) of each position are powers of ten. make it a zero and increment the next place value to the left. 2. 3. 4. Derya Altunay Decimal Numbers 2 102 6 • Binary • Decimal • A number in any weighted-positional number system can be easily converted to an equivalent decimal number by expressing the number as a polynomial in powers of the radix: n D = ∑ xk ⋅ r k k = -m 17 ELE 107 Dr. • A number such as (101. and 1. 1. 8. General formula for converting a number from base r to decimal (xk is the kth digit of the number) 14 Binary number system (base-2): • Uses ten symbols: 0. » 99 becomes 100 (N)r = xn xn-1 xn-2 · · · x1 x0 . Derya Altunay Octal Hexadecimal 00 0 01 1 02 2 03 3 04 4 05 5 06 6 07 7 10 8 11 9 12 A 13 B 14 C 15 D 16 E 17 F 18 3 . Derya Altunay • Uses two symbols: 0. make it a zero and increment the next place value to the left. » 11two becomes 100two Binary Numbers Decimal number system (base-10): 1 101 4 – Each number has a unique representation. 7. Derya Altunay 1 21 0 = (1 x 22) + (0 x 21) + (1 x 20) + (0 x 2-1) + (1 x 2-2) = 5. Derya Altunay Numbers with Different Bases Number Systems Decimal Decimal: Base 10 00 Binary: Base 2 01 02 Octal: Base 8 03 Hexadecimal: Base 16 04 Octal and Hex forms are 05 06 more convenient for 07 humans to use 08 • Don’t have to deal with 09 long and confusing strings 10 11 of 1’s and 0’s 12 • Most computer manuals use13 either octal or hex numbers 14 Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 15 1111 • • • • • (1234)10 = 1 x 103 + 2 x 102 + 3 x 101 + 4 x 100 (1010)2 = 1 x 23 + 0 x 22 + 1 x 21 + 0 x 20 =1x8 + 0x4 + 1x2 + 0x1 = 810 + 210 = (10)10 ELE 107 Dr.

11)2 = 1∗23 + 0∗22 + 1∗21 + 1∗20 + 1∗2-1 + 1∗2-2 = 8 + 0 + 2 + 1 + ½ + ¼ = (11. • A number such as (642. and 7. • A number such as (64F. Find the greatest integer that is a power of 2 and when subtracted from N it yields a positive difference N1 2. D .5)10 (011. 6. 5. 2 1 0 -1 -2 (100. B. 6. Derya Altunay 20 21 22 23 24 25 26 27 28 29 210 211 212 213 214 215 216 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 1K 2K 4K 8K 16K 32K 64K 22 Decimal-to-Binary Conversion (1011. A. E and F. Derya Altunay Hexadecimal number system (base-16): 0 160 6 4 F 1 81 4 0 80 2 26 25 24 23 22 21 20 64+0+16+0+0+2+1 = (83)10 0 21 Binary-to-Decimal Conversion ELE 107 Dr. ELE 107 Dr.1875)10 in the decimal system.ELE 107-Week 2: Number Systems & Binary Codes Numbers with Different Bases • It takes 3 binary digits Decimal 00 (bits) to represent the 01 numbers 0-7 02 • Each group of 3 bits 03 04 corresponds to exactly 05 one octal digit 06 • It takes 4 (bits) to 07 represent the numbers 08 09 0-15 10 • Each group of 4 bits 11 corresponds to exactly 12 one hex digit 13 Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 14 1110 15 1111 Octal Numbers Octal Hexadecimal 00 0 01 1 02 2 03 3 04 4 05 5 06 6 07 7 10 8 11 9 12 A 13 B 14 C 15 D 16 E 17 F 19 ELE 107 Dr.30 )8 will be expanded as: Binary-to-Decimal Conversion Hexadecimal Numbers 2 162 Octal number system (base-8): 23 ELE 107 Dr. Place a 1 in the corresponding bit. 1010011 -1 -2 16 -1 16 -2 3 2 82 6 Each bit in a binary number refers to a power of two: • Uses sixteen symbols: 0. 4. Derya Altunay 24 4 . • The positional values (weights) of each position are powers of eight. Derya Altunay = (6 x 162) + (4 x 161) + (15 x 160) + (3 x 16-1) + (0 x 16-2) = (1615. 2.101) 2 = 1∗2 + 0∗2 + 0∗2 + 1∗2 + 0∗2 + 1∗2 3 = 4 + 0 + 0 + ½ + 0 + ⅛ = (4. 1.75)10 Let N be a decimal integer: Repeated Subtraction 1. Derya Altunay 20 ELE 107 Dr.10)2 = 1∗22 + 1∗21 + 1∗20 + 1∗2-1 + 0∗2-2 = 4 + 2 + 1 + ½ + 0 = (7. Derya Altunay -1 -2 8 -1 8 -2 3 0 = (6 x 82) + (4 x 81) + (2 x 80) + (3 x 8-1) + (0 x 8-2) = (418. Stop when the difference is zero. 2. 3. • The positional values (weights) of each position are powers of sixteen. 7. starting from N1 and finding difference N2 .30 )16 will be expanded as: 1 161 • Uses eight symbols: 0. Place a 1 in the MSB 3.125)10 ELE 107 Dr. Repeat Step 1.001)2 = 0∗22+1∗21+1∗20+0∗2-1+0∗2-2+1∗2-3 = 0 +2 + 1 + 0 + 0 + ⅛ = (3. C. 3.625)10 (111. 1. 9. 4.375)10 in the decimal system. 8. 5.

1 2 6 5 )8 ( 10 110 110 .23 = 9 . Derya Altunay Let N = (715)10 Decimal-to-Binary Conversion Let N= (109)10 Repeated 109/2 = 54 remainder 1 (l.20 = 1 . Read the remainders in reverse order. • 4 bits per group starting from the radix point. Divide the integer successively by 2 until you get to zero 2. Derya Altunay 6 . A 7 F D )16 10 1011 0011 .b) Repeated Division (109)10 = (1101101)2 27 ELE 107 Dr.ELE 107-Week 2: Number Systems & Binary Codes Decimal-to-Binary Conversion Start with decimal integer N = (25)10 Decimal-to-Binary Conversion Repeated Subtraction Subtract largest power of two ≤ N 25 . 1010 0111 1111 1101)2 (3 ( 2 4 7 . 001 010 110 101)2 (0010 0100 1100 . Derya Altunay Decimal-to-Binary Conversion Let N be a decimal integer: 512 = 29 128 = 27 64 = 26 8 = 23 2 = 21 1 = 20 715 – 512 = 203 = N1 203 –128 = 75 = N2 75 – 64 = 11 = N3 11 – 8 = 3 = N4 3 – 2 = 1 = N5 1 – 1 = 0 = N6 (715)10 = 29 + 27 + 26 =(1 0 1 1 0 25 ELE 107 Dr.16 = 9 Subtract largest power of two ≤ Difference 9 . Derya Altunay 28 ELE 107 Dr.b) Division 54/2 = 27 remainder 0 27/2 = 13 remainder 1 13/2 = 6 remainder 1 Read 6/2 = 3 remainder 0 backwards 3/2 = 1 remainder 1 1/2 = 0 remainder 1 (m. • 3 bits per group starting from the radix point. (011 100 111 . 1011)2 ( (2 ( 2 6 ELE 107 Dr. A 7 C )16 30 5 . 5 4 )8 29 4 C .1 = 0 Now.s.s. • Each hex digit is represented by four bits.8 = 1 Subtract largest power of two ≤ Difference 1 . 1010 0111 110)2 B ELE 107 Dr. Derya Altunay 3. 0 Repeated Subtraction + 23 + + 21 + 20 1 0 1 1)2 26 ELE 107 Dr. Derya Altunay Binary ↔ Octal Binary ↔ Hexadecimal • Each octal digit is represented by three bits.24 = 25 . we see (25)10 = 24 + 23 + 20 = (1 1 0 0 1)2 1.

• Go through binary ( much easier! ) Hex Æ Binary Æ Octal Octal Æ Binary Æ Hex 31 ELE 107 Dr.s.d) Fraction part: Read down 0.d) 33 ELE 107 Dr.5 (m.d) 20/8 = 2 remainder 4 2/8 = 0 remainder 2 (m.b) 0.s.6875)10 = ( ? )8 = (247.b) 3/2 = 1 remainder 1 1/2 = 0 remainder 1 (m.5 x 16 = 8.d) ELE 107 Dr.d) 101/16 = 6 remainder 5 6/16 = 0 remainder 6 (m. Derya Altunay 36 6 .1011)2 Integer part: 6/2 = 3 remainder 0 (l.s. and read down. keep track of the integral part until the fraction becomes zero.s.d) 0.s.3750 x 2 = 0. – Multiply the fraction successively by r .s.7500 0.s. Derya Altunay Decimal to Hexadecimal (1631.0000 (l. Derya Altunay Decimal to Binary (6.s.78125 x 16 = 12.s.d) Fraction part: 32 ELE 107 Dr.3750 (m.b) Decimal to Octal Read up (167.s.d) (12 = C) 0.500 (m.ELE 107-Week 2: Number Systems & Binary Codes Octal ↔ Hexadecimal Decimal to any radix r • Go through decimal: Hex Æ Decimal Æ Octal Octal Æ Decimal Æ Hex • Conversion from decimal to radix r system is carried out by separating the number into its integer and fraction parts and converting each part separately.7500 x 2 = 1.s.0 (l.6875)10 = ( ? )2 = (110.54)8 Integer part: 167/8 = 20 remainder 7 (l.5000 0.000 (l.78125)10 = ( ? )H = (65F. Derya Altunay Read up Read down ELE 107 Dr.500 x 8 = 4.b) Fraction part: 0.s.6875 x 8 = 5. Derya Altunay 0.6875 x 2 = 1.C8)H Integer part: 1631/16 = 101 remainder 15 = F (l.5000 x 2 = 1. Derya Altunay 34 Notes on Fractions • Radix point (number point) – – – – Read up Decimal point in base 10 Binary point in base 2 Octal point in base 8 Hex point in base 16 • Integer and fraction parts must be converted separately Read down 35 ELE 107 Dr. – Divide the integer successively by r and collect the remainders backwards (read up).

5000 x 2 = 1.6875 x 2 = 1.74)8 0.6)10 (4276)10 • Shift the radix point one place to the left • No exact relationship between fractional numbers in different number bases – Effect: divides the number by the base number – Exact conversion may not be possible – Example: (427.6)10 37 ELE 107 Dr.65625)10 (0.656 0.6875)10 = (0.832 x 8 = 6.248 0. Derya Altunay Notes on Fractions 0. .3750 x 2 = 0.104 x 8 = 0.832 0.5000 (terminates) (0.009 .0000 (terminates) ELE 107 Dr.5000 0. Derya Altunay (42.0000 0.4293)10 Position 10-1 10-2 10-3 10-4 Value 1/10 1/100 1/1000 1/10000 Position 2-1 2-2 2-3 2-4 2-5 Value 1/2 1/4 1/8 1/16 1/32 Evaluate 4 x 1/10 2 x 1/100 9 x 1/1000 3 x1/1000 Evaluate 1 x 1/2 0 x 1/4 1x 1/8 Sum Sum .02 .5 0 x 1/16 1 x 1/32 41 0.7500 x 2 = 1.9375)10 = (0.1011)2 (0.513 x 8 = 4.248 x 8 = 1. Derya Altunay 42 7 .104 0.7500 0.9375 x 8 = 7.76)10 38 ELE 107 Dr. Derya Altunay Notes on Fractions Notes on Fractions (0.513)10 = (?)8 0.5000 x 8 = 4. (does not terminate!) ELE 107 Dr.0003 39 ELE 107 Dr.ELE 107-Week 2: Number Systems & Binary Codes Notes on Fractions Notes on Fractions • Radix point: fixed reference for the conversion • Shift the radix point one place to the right – Digit to the left is a unit digit in every base – (Base)0 is always 1 regardless of the base – Effect: multiplies the number by the base number – Example: (427. Derya Altunay .125 ELE 107 Dr. Derya Altunay 0.4 .03125 40 Notes on Fractions (0.984 .656 x 8 = 5. .3750 0.10101)2 = (0.

images.ELE 107-Week 2: Number Systems & Binary Codes Notes on Fractions Notes on Fractions (0.g.400 • No general relationship between fractions of types 1/10k and 1/2k – A number representable in decimal may not be representable in binary – The converse is true: all fractions of the form 1/2k can be represented in decimal • Fractional conversions from one base to another are stopped – If there is a rational solution or – When the desired accuracy is attained … (repeates!) 43 ELE 107 Dr.400 x 8 = 3. Derya Altunay ELE 107 Dr. Binary Numbers ELE 107 Dr.975)10 = (?)8 = (0.800 x 8 = 6. and images are displayed on the screen 216-1 • Integer range: 0 to (0 to 65535) 16 • Fraction range: 0 to (2 -1) / 216 (0 to 65535/65536 = 0.200 0.. numbers.76314)8 0. we use • Assume a computer is processing 16-bit unsigned integers and fractions: Integer part (16-bit) – Digits to represent numbers – Letters to represent text Fraction part (16-bit) • When we communicate with a computer: – Text and numbers are entered through keyboard/mouse – Text. sounds ??? Text.600 0. numbers.400 0. numbers. – How do humans store the information “internally”? – How do computers store the information “internally”? 45 ELE 107 Dr. the information is represented in an understandable notation. Derya Altunay Number Ranges Data Representation • When we communicate with each other.800 x 8 = 6. images.975 x 8 = 7. Derya Altunay ELE 107 Dr. sounds Text. numbers. images.800 0. sounds 44 47 ELE 107 Dr.9999847412) • This may be referred to as an external representation.600 x 8 = 4. Derya Altunay 48 8 . Derya Altunay Data Representation • Humans: • Computers: • The five types of data/information the computer commonly manipulates: – – – – – Text.200 x 8 = 1. Derya Altunay 46 Data Representation Internal Text. sounds Numeric Character Visual Audio Instructional • First. the data must be transformed (converted) into an acceptable representation that the computer will accept. e. numbers.800 0.

black and white. 01101010 might instruct the computer to add two numbers. or ON and OFF 52 ELE 107 Dr.ELE 107-Week 2: Number Systems & Binary Codes Binary Systems Binary Systems • The system in which all computer data is represented and manipulated is called the binary system. Hot ELE 107 Dr. Derya Altunay 54 9 . Derya Altunay 53 ELE 107 Dr. Derya Altunay Bits as Instructions Off/On Switches • Larger chunks of information are stored by grouping bits as units • The computer can represent data by constructing combinations of off or on switches. codes. Derya Altunay Binary Systems • Binary systems have two values – Zero and One • Binary numbers are easy to represent using physical phenomena • All numbers can be represented in binary as well as in any other base Zero ‘0’ False Off Low V 0V Current N-S polar. – Use only two symbols: 0 and 1. • All modern computers work with a system of numbers called binary numbers. • Binary circuits: Electronic devices are cheapest and function most reliably if they assume only two states. Derya Altunay 51 • A bit (binary digit) ON OFF – is the smallest unit of information – can have two values – can represent numbers. Cold 50 ELE 107 Dr. Open circuit Closed circuit 49 ELE 107 Dr. Derya Altunay Binary Systems One ‘1’ True On High V 5V No current E-W polar. ELE 107 Dr. – 8 bits (byte) = 256 different messages • The computer stores programs as collections of bits. or instructions • Think of these values as switches: yes and no. high and low. – For instance. OFF or ON • Other bit instructions might include where to find numbers stored in memory or where to store them.

or 0 one bit two bits 1 three bits Zero (off) and one (on) make up the two digits in the binary system. Derya Altunay 0 • Each byte represents one character of data (a letter.ELE 107-Week 2: Number Systems & Binary Codes Zero or One? The Bit • The binary system can also be represented by the digits zero and one. Derya Altunay Representation of Numbers The Byte • A group of 8 bits is called a byte. • The three-light system: – Has eight possible combinations on and off. 55 ELE 107 Dr.741. Derya Altunay 60 10 . 56 ELE 107 Dr. Intel Itanium 64 bits 59 ELE 107 Dr. 3. 0 = 000 4 = 100 1 = 001 5 = 101 2 = 010 6 = 110 3 = 011 7 = 111 0 0 0 1 0 1 0 1 0 0 1 0 1 0 = J Storing Bytes ELE 107 Dr. 5. 4. Derya Altunay 1 8 bits = 1 byte = one word length 32 bits = 4 bytes = one word length 64 bits = 8 bytes = one word length • Different computers use different numbers of bits: Intel Pentium 32 bits . Derya Altunay 58 Computer Word • Storage and memory capacity is expressed in the number of bytes they can hold: • A computer word is defined as the number of bits that constitute a common unit of data.073. 57 ELE 107 Dr. Derya Altunay • Each 0 or 1 in the binary system is called a bit.824 bytes 1 terabyte (TB) = 240 or about one million MB 1 petabyte (PB) = 250 or about one million GB ELE 107 Dr. 7. For example: 1 kilobyte (KB) = 210 or 1024 bytes (1K) 1 megabyte (MB) = 220 or 1. • Word length varies by computer. or special character). 2. 6.048. digit.576 bytes 1 gigabyte (GB) = 230 or 1. 1. • Could be used to indicate the numbers 0.

perform operations in binary. government and is found in a variety of computers.S. 65 ELE 107 Dr. but people are accustomed to the decimal system. • Therefore. • We represent the decimal digits by a binary code. Derya Altunay • The length of the codeword is the number of bits in the codeword. that is a sequence of 1’s and 0’s. Derya Altunay 63 Binary Codes for Decimals Terminology • A codeword (encoding) is a symbolic representation based on the binary alphabet. 0 1 0 0 1 0 1 0 ASCII-8 code = • ASCII . Derya Altunay 61 62 ELE 107 Dr.American Standard Code for Information Interchange – Most widely used code. • So. the I/O generally uses decimal numbers (human-interface). Binary Codes ELE 107 Computers and Programming I ELE 107 Dr. Derya Altunay 64 ELE 107 Dr. • ASCII has been adopted. and convert the binary results back to decimal. we have to store the decimal numbers in the computer in a way that they can be converted to binary. Derya Altunay 66 11 . represents each character as a unique 8-bit code. by the U.ELE 107-Week 2: Number Systems & Binary Codes Coding the Computer Bits as Codes • A code for determining which group of bits represent which characters on a keyboard is called ASCII. Derya Altunay Binary Codes for Decimals • The binary number system is the most natural system for the computer. as the standard. • Computers work internally with binary numbers. convert decimal numbers to binary. 0110010 has a length of seven. For example. ELE 107 Dr. J Keyboard character ELE 107 Dr.

• At least four bits are necessary to represent the ten decimal digits (6 are unused) . ELE 107 Dr. • A code is a set of codewords.01. a set of 4 distinct numbers can be represented by 2-bit codes such that each number in the set is assigned exactly one of the combinations in {00.10. Derya Altunay BCD BCD Decimal Symbol 0 1 2 3 4 5 6 7 8 9 • BCD is different from converting a decimal number to binary. 111 } is a code that has five codewords. the set {110. • There are many different ways to choose ten 4-bit codewords. is (1100001)2. when converted to binary. Derya Altunay BCD Digit 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 72 12 . • Because each codeword has the same length.ELE 107-Week 2: Number Systems & Binary Codes Terminology Terminology • An n-bit binary code is a group of n bits that assume up to 2n distinct combinations of 1’s and 0’s. Derya Altunay Terminology BCD • If m symbols are to be encoded then 2n ≥ m must be satisfied.11}. • Each decimal digit is represented by a 4-bit unsigned binary number. Derya Altunay 71 ELE 107 Dr. • Multiple digit decimal numbers are represented by coding each of the digits. it is easier to understand and interpret. • 97 when represented in BCD is (1001 0111)BCD. • Variable-length codes have codewords with different lengths. • A code that uses n-bit strings need not contain 2n valid codewords. • For example. Derya Altunay 70 ELE 107 Dr. 001. 011. this is a fixed-length code. For example. 67 ELE 107 Dr. Derya Altunay 68 ELE 107 Dr. 69 ELE 107 Dr. • For example (97)10 . • BCD numbers are decimal numbers even though they are represented in bits. • The most popular and natural decimal code is called binary-coded decimal (BCD). • Although BCD requires more bits. 101.

Derya Altunay Other codes for decimals Other codes for decimals • The 2421 code and the Excess-3 (XS-3) code are both examples of self-complementing codes. • The last five bits indicate which of the five numbers in the selected range is represented. brake systems. etc. • The bits are multiplied by indicated weights and the sum gives the decimal digit. Derya Altunay 73 74 ELE 107 Dr. Derya Altunay Other codes for decimals Gray Code • The biquinary code uses seven bits for each decimal digit. Derya Altunay 78 13 . machine tools. • Self-complementing property is useful when performing operations such as subtraction. • The 2421 code is a weighted code. • An important cyclic code is the Gray code. 2. • XS-3 code is obtained from the corresponding BCD code added to 3. • XS-3 code is useful in decimal subtraction. • Continuous. • The XS-3 code is a nonweighted code. • The Gray code. • The weights are 8. • The first two bits indicate whether the digit is in the range 0-4 or 5-9. ELE 107 Dr. is sometimes used for the converted digital data. or analog.ELE 107-Week 2: Number Systems & Binary Codes BCD • BCD is a weighted code because each decimal digit can be obtained by assigning a fixed weight to each codeword bit. information is converted into digital form by means of an A/D converter. ELE 107 Dr. • Used in electromechanical applications of digital systems. Derya Altunay 75 76 ELE 107 Dr. Any advantage using more than the minimum number of bits in a code ? • Sometimes it is desirable to use codes in which all successive codewords differ in only one bit (cyclic codes). etc. • Self-complementing property:The 9’s complement of each digit (9-d) is obtained by complementing each bit in the codeword. and 1 ⇒ 8421 code • Other binary codes besides BCD exist to represent decimal digits: – 2421 code – Excess-3 (XS-3) code – Bi-quinary code – 1-out-of-10 code. such as copy machines. Derya Altunay 77 ELE 107 Dr. 4. ELE 107 Dr.

If this does not happen. Derya Altunay 84 14 . i. • Using the Gray code keeps the value from being misrepresented in such cases. • The Gray code is also an example of a “reflected code” . then various illegitimate numbers could be momentarily generated during the transition.ELE 107-Week 2: Number Systems & Binary Codes Gray Code Gray Code • The Gray code is a code in which only one bit of a codeword changes between each pair of successive codewords. or Unicode) » Facilitates sorting and searching ELE 107 Dr. Derya Altunay ELE 107 Dr. switching from 7 (0111) to 8 (1000) requires four bits to be changed simultaneously. Derya Altunay 82 Representing Characters • ASCII : most widely used coding scheme • Unicode : developed for worldwide use • Arbitrary choice of bits to represent characters – Standard (consistency): input and output device must recognize same code – Value of binary number representing character corresponds to placement in the alphabet ASCII file often used as a synonym for text file (Although a text file can be encoded in ASCII code. Derya Altunay Gray Code • Binary to Gray : Data Types: Alphanumeric • Alphanumeric: g n = bn g i = bi ⊕ bi +1 . Derya Altunay – – – – 81 Alphanumeric Codes ELE 107 Dr.. ZIP codes (1 0 1 1 0 1)GRAY = (1 1 0 1 1 0)2 ELE 107 Dr. the n-bit code can be obtained by reflecting the (n -1)st-bit code. numbers bn = g n – Both entered as ordinary characters – Computer converts into numbers for calculation bi = g n ⊕ g n −1 ⊕ L ⊕ g i » Examples: Variables declared as numbers by the programmer ( 0 ≤ i ≤ n − 1) – Treated as characters if processed as text » Examples: Phone numbers. • Gray code counters are sometimes used to provide the timing sequences that control the operations in a digital system. • This is useful when the analog signal is on the border between two of the binary coded values. 79 ELE 107 Dr.e. • For example. 0 ≤ i ≤ n −1 (1 0 0 1 1 0)2 = (1 1 0 1 0 1)GRAY • Gray to Binary : 80 Characters: a b X Y Number digits: 0 1 8 9 Punctuation marks: : . Derya Altunay 83 ELE 107 Dr. ? ! Special-purpose characters: # & $ % • Numeric characters vs.

• The printable characters can be generated by typing the appropriate keys on keyboards. Derya Altunay 86 ELE 107 Dr. Derya Altunay ASCII ELE 107 Dr.Z) More miscellaneous characters [ \ ] ^ _ ' Alphabetic (lower case a . Arabic numerals. ELE 107 Dr. mathematical operations Characters 0 – 9 Comparators and other miscellaneous characters : . ? @ 65 .90 91 – 96 97 – 122 123 – 127 Alphabetic (upper case A .57 58 – 64 Punctuation. • The remaining characters are the printable characters.s.s. • This extra bit is used for specific purposes: – Latin alphabet.ELE 107-Week 2: Number Systems & Binary Codes ASCII ASCII • Developed by ANSI (American National Standards Institute) • American Standard Code for Information Interchange. • The control characters include the first 32 characters and the last character (delete). • The control characters can be generated by holding down the control key while typing a single character.b set to 0. Derya Altunay ASCII 87 Control and Printable Characters ELE 107 Dr.b set to 1. Derya Altunay 90 15 . – As a parity bit (check for memory/communication errors) 85 ELE 107 Dr. Derya Altunay 88 Control and Printable Characters • Two subsets in the ASCII character set: the control characters and the printable characters. • The standard alphanumeric binary code • Represents • ASCII is an example of a fixed-size code with a code length of seven • Basic ASCII uses 7 bits to code 128 characters • Most computers manipulate the 7-bit ASCII code as a byte with the m. standard punctuation characters – Plus small set of accents and other European special characters – An additional 128 8-bit characters with the m. Derya Altunay 89 Decimal 0 – 31 ASCII Invisible (control characters) 32 – 47 48 .z) More miscellaneous characters { | } ~ DEL ELE 107 Dr.

• Then match each subsequence to a character using the ASCII table. Derya Altunay 94 First 256 Codes for Unicode Chess symbols in Unicode U+2654 (alt-09812) WHITE CHESS KING U+2655 (alt-09813) WHITE CHESS QUEEN U+2656 (alt-09814) WHITE CHESS ROOK U+2657 (alt-09815) WHITE CHESS BISHOP U+2658 (alt-09816) WHITE CHESS KNIGHT U+2659 (alt-09817) WHITE CHESS PAWN ELE 107 Dr. Java. it is easy to decode sequences of encoded characters. most software.536 symbols. Derya Altunay 96 16 . Japanese and Korean – Composite characters for vowels and syllabic clusters required by some languages o ELE 107 Dr. • Start breaking the sequence into subsequences consisting of 7 bits.ELE 107-Week 2: Number Systems & Binary Codes Decoding Unicode • Since ASCII is a fixed-length code. Decode the ASCII string : 10010001100101110110011011001101111 • Most common 16-bit form represents 65. Derya Altunay 91 ELE 107 Dr. Derya Altunay 95 ELE 107 Dr. H e l l – Values 0 to 255 in Unicode table • Multilingual: defines codes for – Nearly every character-based alphabet – Large set of ideographs for Chinese. Derya Altunay Some characters in Unicode 92 Some characters in Unicode U+2601 (alt-09729) CLOUD = cloudy weather U+2602 (alt-09730) UMBRELLA = rainy weather U+2603 (alt-09731) SNOWMAN = snowy weather U+03C0 GREEK SMALL LETTER PI U+262F (alt-09775) YIN YANG U+042F CYRILLIC CAPITAL LETTER YA U+263A (alt-09786) WHITE SMILING FACE U+97F3 CJK UNIFIED IDEOGRAPH-97F3 U+263B (alt-09787) BLACK SMILING FACE U+00E6 LATIN SMALL LETTER AE U+221E INFINITY ELE 107 Dr. • ASCII Latin-I subset of Unicode 1001000 1100101 1101100 1101100 1101111 • Allows software modifications for local languages • Unicode used by Web browsers. Derya Altunay 93 ♪ U+266A (alt-09834) EIGHTH NOTE = quaver ♫ U+266B (alt-09835) BEAMED EIGHTH NOTES = beamed quavers ELE 107 Dr.

Derya Altunay Received symbol S R Q W [ C c ^S 100 Hamming Distance • The Hamming distance defines a distance between two codewords. Derya Altunay 98 ELE 107 Dr. • Each machine provides a limited set of characters called the character set of the machine. 1101) = 3 dist (1010. • Error correction is frequently called error masking because errors are not visible to any part of the system other than the receiver. 97 ELE 107 Dr. The detected errors cannot be corrected. • To simplify the presentation. • Changes to bits are frequently called bit flips because the change flips the bit from 0 to 1 or from 1 to 0. 0110) = 3 ELE 107 Dr. • Machine cannot provide a direct representation for every character we use (There are many symbols and new symbols are created). ELE 107 Dr. • The goal of error correction is to correct any errors that occur during transmission.ELE 107-Week 2: Number Systems & Binary Codes Character Encodings Error Detection/Correction • Characters are symbols that we use in written communication. • We ignore the possibility of inserting or deleting bits. Derya Altunay 102 17 . but can prompt the data to be retransmitted. • Now almost every manufacturer uses the ASCII character set. only fixed-length codes will be considered. Derya Altunay 101 • We generalize the Hamming distance to a code by considering the elements of the code in a pair-wise fashion. 0110) = 2 The Hamming distance is 2. we need to change the first and the second bits in the first pattern. ELE 107 Dr. Derya Altunay Bit Flip Example Suppose that you Bit send the ASCII flipped encoding for the none character “S” 0 (101 0011). What is the Hamming distance of the following code? { 1010. What is the Hamming distance between 1011001 and 1011010? • To convert the first pattern to the second . • The storage or transmission of an encoded value can incorrectly change the value. dist (1101. 1 Show the 2 different values 3 that a receiver 4 will receive if a 5 single bit is flipped during 6 transmission. 0110 } dist (1010. • We only consider errors that change individual bits. • The Hamming distance between the two patterns is 2. 1101. • Given a fixed-length code. you count the number of bits in the first codeword that need to be changed to result in the second codeword. Derya Altunay 99 Hamming Distance Received pattern 101 0011 101 0010 101 0001 101 0111 101 1011 100 0011 110 0011 001 0011 ELE 107 Dr. the Hamming distance for the code is the minimum distance between any two codewords in the code. the goal is to detect errors that occur. • We can use an error detection or an error correction strategy to limit the scope of that change. • In error detection.

• Given a codeword. changing a single bit in any of the codewords will result in a bit pattern that is not in the code. • The parity of a binary pattern is determined by counting the number of 1’s in the pattern. • Then we add a parity bit to the ASCII code. • A code with a minimum distance of 2c + d + 1 can correct up to c bit errors and detect up to additional d bit errors. Derya Altunay 106 ELE 107 Dr. • If a code has a Hamming distance of two. we can decide if an error introduced a single bit flip. • The simple parity scheme provides us with enough information to detect a single error. ELE 107 Dr. Derya Altunay Parity Bit Example Symbol 0 1 2 3 A d # • The parity bit is extremely important when two computers exchange information. • 10111011 and 10010011 is ? 10111011 10010011 it is 2 • 91738254 and 92337254 is ? 91738254 92337254 it is 3 • COMPUTATION and CALCULATION is ? COMPUTATION CALCULATION it is 4 103 ELE 107 Dr. 105 ELE 107 Dr. Derya Altunay Even parity 0011 0000 1011 0001 1011 0010 0011 0011 0100 0001 1110 0100 1010 0011 Odd parity 1011 0000 0011 0001 0011 0010 1011 0011 1100 0001 0110 0100 0010 0011 108 18 . it has odd parity. the code must have a Hamming distance of at least two.ELE 107-Week 2: Number Systems & Binary Codes Hamming Distance Hamming Distance The Hamming distance between: • The Hamming distance for the code reflects the degree of redundancy in the code. • Thus. Derya Altunay 107 ASCII 011 0000 011 0001 011 0010 011 0011 100 0001 110 0100 010 0011 ELE 107 Dr. • If the number of 1’s is even. Derya Altunay Parity Parity Bit • Parity provides a simple way to ensure that the Hamming distance of a code is at least two. What is the parity of the pattern 1010111? • To ensure that every codeword has the same parity. the parity bit is the 8th bit in the codeword. we set the parity bit to 1 or 0 to make sure that the resulting bit pattern has the desired parity. we add a bit called the parity bit. to each codeword. then the pattern has even parity . Derya Altunay 104 ELE 107 Dr. Because the pattern has five 1’s. but not enough to correct it. • The sender and the receiver must agree on the type of parity. • If every codeword in a code has the same parity. otherwise. the pattern has odd parity.