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
Embed
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
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
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
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
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
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!
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
Fesq, 2/28/01 6 16.070
What is Octal?
• Octal means base 8 - Use powers of 8 for each position.
! 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.
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…
• 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)
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
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
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.
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
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
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
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….
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