Top Banner
Fesq, 2/28/01 1 16.070 Data Representation 2/28/01 Lecture #10 16.070 Radix Number Systems ! Define Binary, Octal, Hexadecimal ! Conversion between different radix number systems Memory Error Detection and Correction Reference: "Structured Computer Organization" by Andrew Tanenbaum
24

Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Apr 08, 2018

Download

Documents

vonhu
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 1 16.070

Data Representation2/28/01 Lecture #10 16.070

• Radix Number Systems

! Define Binary, Octal, Hexadecimal

! Conversion between different radix number systems

• Memory Error Detection and Correction

• Reference: "Structured Computer Organization" by AndrewTanenbaum

Page 2: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 2 16.070

Binary - the Number System of Computers

• Humans count using decimal - base 10

! Why base 10? 10 fingers? 10 toes?

! Numbers available are 0 -> 9

! Position represents a power of 10538210 = 5x10

3 + 3x102 +8x101 +2x100

• Computers have only 2 fingers, and count using binary - base 2

! Numbers available are 0 -> 1 (off/on)

! Bit position represents a power of 210112 = 1x23 + 0x22 + 1x21 + 1x20

= 8 + 0 + 2 + 1 = 1110

Page 3: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 3 16.070

Bytes - the Representation of Numbers in Computers

• A Byte = 8 bits used to represent data

! Example: 010100112! Bit #7 = most significant bit (msb), Bit #0 = least significant bit (lsb

! Decimal value of 000000112? 010100112?

! Largest value represented by a byte?

! 000000002 = 010. 111111112 = 25510

0 1 0 1 0 0 1 1

7 6 5 4 3 2 1 0

1248163264128

bit number

bit value

Page 4: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 4 16.070

Representing Negative Numbers - Sign Magnitude

• Using one byte, suggestions for representing negative numbers?

! E.g., 000100112 = 1910. How to represent -1910 in binary?

• Sign Magnitude - Reserve 1 bit (#7) for sign, 7 bits (#0-#6) for number

! 000000012 = 110. 100000012 = -110

! 000100112 = 1910. 100100112 = -1910

! Range of numbers represented?

! Two representations for 0: 000000002 and 100000002. Wasteful and confusing!

Page 5: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 5 16.070

Representing Negative Numbers - One's & Two's Complement• One's Complement - Invert each bit

! 000100112 = 1910. 111011002 = -1910! Range is

! Again, two representations for 010: 000000002 and 111111112.

• Two's Complement - Invert each bit and add 1

! 000100112 = 1910. 111011012 = -1910! Range is

! Try to negate 0:a) 010 = 000000002

b) invert: 000000002 -> 111111112

c) add 1: 111111112 + 000000012 = 000000002

Page 6: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 6 16.070

What is Octal?

• Octal means base 8 - Use powers of 8 for each position.

1058 = 1 x 82 + 0 x 81 + 5 x 80 = 6910

• Octal requires only 8 single-digit numbers: 0, 1, 2, 3, 4, 5, 6, 7

• One octal digit can be represented using 3 binary bits

! Examples: 0012 = 18 1102 = ? 8

1012 = ?8 1112 = ? 8

• How many octal digits are needed to represent an 8-bit byte?

Page 7: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 7 16.070

What is Hexadecimal?

• Hexadecimal means base 16 - Use powers of 16 for each position.

10516 = 1 x 162 + 0 x 161 + 5 x 160 = 26110

• Hex requires 15 single-digit numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ?????

! Requires extra characters to represent 1010 - 1510. Use A - F

• One Hex digit can be represented using 4 binary bits = nibble.

! Examples: 00012 = 116 11002 = ? 16

00102 = 216 11112 = ? 16

• Two Hex digits corresponds exactly to an 8-bit byte.

! Examples: 1001 00012 = 9116 0101 11002 = ? 16

• Hex is useful for understanding raw data without having to look atindividual bits

Page 8: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 8 16.070

Numbers Represented in Radix Number SystemsDecimal Binary Octal Hexadecimal

0 0 0 01 1 1 12 10 2 23 11 3 34 100 4 45 101 5 56 110 6 67 111 7 78 1000 10 89 1001 11 910 1010 12 A11 1011 13 B12 1100 14 C13 1101 15 D14 1110 16 E15 1111 17 F16 10000 20 1017 10001 21 11

Page 9: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 9 16.070

Conversion Binary <-> Octal / Hex

• To convert binary to hex

! Separate binary digits into groups of 4, starting with the right-most-bit (lsb)

! Label each group with the corresponding hex digit

Binary: 1 0 0 0 1 0 0 1 1 1 0 0 0 0 1 1_______ _______ _______ _______

Hex: 8 9 C 3

• To convert binary to octal

! Separate binary digits into groups of 3, starting with the right-most-bit (lsb)

! Label each group with the corresponding octal digit

! May be necessary to add leading zeros to fill out a group to 3 bits

Binary: 1 0 0 0 1 0 0 1 1 1 0 0 0 0 1 1_ _____ _____ _____ _____ _____

Octal: 1 0 4 7 0 3

Page 10: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 10 16.070

Conversion Binary <-> Decimal

• To convert binary to decimal

! Sum up the powers of 2 corresponding to the 1 bits in the number

• To convert decimal to binary

! Subtract largest power of 2 from the number. Repeat on difference.Assemble binary number with 1s in bit positions corresponding to powersof 2 used in decomposition, 0s elsewhere.

Page 11: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 11 16.070

An Example of Hex Usage -- Spacecraft Telemetry

• Hex is often used in processing telemetry from a spacecraft.

• Data transmitted from the spacecraft to the ground is a stream of bits -1's and 0's: 1000010100001100111111111001…

• Format into tables

1000 0101 0000 1100 1111 11111001 1010 1111 1101 ...

1100 1010 0000 1100 1111 11111001 1010 1110 1101 ...

1010 0011 0000 1100 1111 11111001 1010 1101 1101 ...

TLM Frame #1 TLM Frame #2 TLM Frame #34096 bits 4096 bits 4096 bits

85 0C FF 9A FD ... CA 0C FF 9A ED ... A3 0C FF 9A DD ...

TLM Frame #1 TLM Frame #2 TLM Frame #34096 bits 4096 bits 4096 bits

binary

hex

Page 12: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 12 16.070

Masks - Accessing Bits in a Byte

• How to access one bit inside of a byte?

• In telemetry, often one bit corresponds to ON/OFF state of a box

• Example: Assume first byte in telemetry is Gyro Status, and Bit #4 isGyro power state (0=OFF, 1=ON)

Frame #1 Gyro Status = 85 = 1000 01012 => Gyro is OFF

Frame #2 Gyro Status = CA = 1100 10102=> Gyro is OFF

Frame #3 Gyro Status = A3 = ? ?2 => Gyro is ?

• Easy for human to determine state, once translated to binary. Can youdefine an algorithm to determine the state of the Gyro?

• Hint: Compare to every possible value that has that bit set to 0? (00,20, 40, 60, 80, A0, C0, E0, 01, 21, 41, etc)

Page 13: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 13 16.070

ANDx y

0

1

0

1

0

000 10

1 1

Using Masks to Isolate One Bit

• Solution - mask off all other bits and then compare result with mask

• Use the AND operator (use ampersand character "&" in C)

! AND operator compares two numbers, bit-by-bit. For each bit position,result is 1 iff both inputs were 1. All bits combined with 0 result in 0:

Truth Table0 AND 0 = 0

0 AND 1 = 0

1 AND 0 = 0

1 AND 1 = 1

Page 14: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 14 16.070

Examples of Masking One Bit

• To extract state information for a particular bit, mask off all other bitsby ANDing with 0. Only desired bit is ANDed with 1.

----- -----

10102 10102

AND 10002 <-MASK AND 01002 <-MASK10002 00002

10102 10102

AND 00102 <-MASK AND 00012 <-MASK00102 00002

Page 15: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 15 16.070

Example of Masking Spacecraft Data

• Now perform Masking on Gyro Status Word in Telemetry Frame #3:

! Gyro Status = A3

! Convert to binary: A3 = 1010 00112! Apply mask

1010 00112

AND 0001 00002 <- MASK0000 00002

! Once masking is performed, result can be compared to maskIf A316 AND 1016 = 1016, then Gyro is ON.

If A316 AND 1016 = 0016, then Gyro is OFF.

Page 16: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 16 16.070

Using Masks to Extract Multiple Bits

• What if desired data cannot be represented using one bit?

! Gyro can be in High-, Medium-, or Low-rate range

! How many bits would be needed to represent this information?

! Using same telemetry Gyro Status Word = A3, bits #1 and #2 representHi/Med/Low states as follows:

#2 #1

002 = Low rate range012 = Medium rate range102 = High rate range

! Use a mask with bits #1 and #2 set to 1 to isolate desired bits: 1010 00112AND 0000 01102 <- MASK

0000 00102= Medium rate range

Page 17: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 17 16.070

Error Detection and Correction (EDAC)

• Errors in data representation can be caused by factors such as noisytransmission (phone lines, radio links), power surges, or Single EventUpsets (SEUs)

• Bits can flip during transmission or on orbit inside spacecraftprocessors

• What if bit is in the wrong state?

! One bit flip can have dramatic ramifications

! Must develop and use routines to− Detect single bit errors− Correct for single bit errors (for system critical information)− Make sure communication link and on-board processors are robust

enough that more than one bit error per word is extremely unlikely

Page 18: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 18 16.070

Parity Coding

• Parity Coding is a coding method for detecting bit errors

• Includes an additional bit to each byte to control the number of “1” bitsto be even (even parity) or odd (odd parity)

P E 27 26 25 24 23 22 21 20

6510 0 0 1 0 0 0 0 0 1 (sum of 1's is even )6610 0 0 1 0 0 0 0 1 0 (sum of 1's is even)6710 1 0 1 0 0 0 0 1 1 (sum of 1's is odd)

• Note that even/odd parity is a different concept than even/odd numbers

• Upon reception, decoding again calculates what parity bit should be

! If transmitted an recalculated parity bit agree, accept byte

! If disagree, reject byte

Page 19: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 19 16.070

Limitations of Parity Coding

• Parity can detect when 1 bit in the word has changed.

• What if >1 bit changes?

• Parity can not tell if an even number of bits have changed

• Parity can not tell which bit in the word has changed

=> Next Challenge: determine which bit is in error….

Page 20: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 20 16.070

Hamming Code

• Hamming Coding is a coding method for detecting and correctingerrors

! Number bits from left to right, starting with 1

! All bits whose bit number is a power of 2 are parity bits

! Each parity bit checks specific bit positions. For an 8-bit word:Bit 1 checks 1, 3, 5, 7, 9, 11Bit 2 checks 2, 3, 6, 7, 10, 11Bit 4 checks 4, 5, 6, 7, 12Bit 8 checks 8, 9, 10, 11, 12

! Generalize: bit n is checked by those parity bits that sum to n:b1 + b2 + … + bj = n

Page 21: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 21 16.070

Hamming Code - Example

• 6510 = 0100 00012

• Hamming code representation (Even Parity)

1 0 0 0 1 0 0 1 0 0 0 1pos 1 2 3 4 5 6 7 8 9 10 11 12ck by b1 1 1 1 1 1 1ck by b2 2 2 2 2 2 2ck by b4 4 4 4 4 4ck by b8 8 8 8 8 8

• Cost is 4 bits to detect and correct 1 bit errors in 8 bits

• Note: even checks and detects errors in 4 parity bits

Page 22: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 22 16.070

Hamming Code – Example (cont.)

• Assume bit 6 was changed during transmission

! Receiver would recalculate parity bits

! Parity bits 2 and 4 incorrect

! Parity bits 1 and 8 correct

! Only bit which is common to 2 and 4, and not common to 1 and 8, is 6

! Bit 6 can be corrected to true value

• A simple method to find incorrect bit is to add up all incorrect paritybits. The sum is the position of the incorrect bit.

Page 23: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 23 16.070

Advanced Error Detection

• More elaborate routines are used on-board spacecraft to perform SingleError Correction, Double Error Detection - SECDED

• Hamming Code required 4 additional bits to detect 1 bad bit out of 8

• Additional capabilities such as double bit error detection requireadditional bits

• Note: Error detection is different from encryption

! Error Detection - ensure data is correct when received

! Encryption - ensure data is unreadable when received by unauthorized user

Page 24: Tanenbaum Radix Number Systems - MITweb.mit.edu/16.070/www/year2001/Data_Representation.pdf · = 255 10 01010011 76543210 1 2 4 8 16 32 64 128 bit number ... Solution - mask off all

Fesq, 2/28/01 24 16.070

Review

• Data are represented in a computer using bits - binary Radix system

• For humans to understand raw data, conversion to octal, hex, ordecimal

• Bits are susceptible to upsets in space, and must be protected - EDAC

• Notes

! Problem Set 2 will be handed back on Friday

! Problem Set 4 is on the web

! Exam questions will cover material from lectures, recitations, labs, problemsets, or readings