59
CSC 370 (Blum) 1 A few more things about binary numbers

CSC 370 (Blum)1 A few more things about binary numbers

Embed Size (px)

Citation preview

Page 1: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 1

A few more things about binary numbers

Page 2: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 2

Errors

• Recall that using a binary representation maximizes our tolerance of fluctuations without loss of the information represented.

• Still errors occur. They have fall into two categories: – Errors that cannot be interpreted as a 1 or 0– Flipped bits: interpreting a 1 where a 0 should

be and vice versa.

Page 3: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 3

Error Detection and Correction

• One may worry about errors wherever data is held temporarily, stored semi-permanently or transmitted.

• The discovery that a bit or bits were flipped is known as error detection.

• The restoration of the correct data is known as error correction.

Page 4: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 4

Error-checking protocols• Data being transmitted by a modem is chunked

into "blocks" of a certain byte size and sent to the destination modem.

• The destination modem checks each block for errors and returns – ACK if no errors are found – NAK if errors are found, which leads to a

retransmission.

• The kind of checking (checksum or cyclic redundancy checking) varies from protocol to protocol.

Page 5: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 5

BER

• The bit error rate (BER) is the ratio of bits having errors (opposite of the value they are supposed to have 01 or 10) to the total number of bits sent

• It is often expressed as ten to a negative power. • For example, a BER of 10-6, means that on

average, for every million bits sent, one error occurs.

Page 6: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 6

BER (Cont.)

• The BER indicates how often a packet has to be resent.

• Sometimes increasing the data transmission rate also increases the BER, making it actually beneficial to reduce the transmission rate so that fewer packets need to be resent.

• A BERT (bit error rate test or tester) is a procedure or device that measures the BER.

Page 7: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 7

Error Detection (Cont.)

• Error detection schemes involve transmitting additional information which the receiver can use to validate the data.

• Error detection can inform the receiver of the presence of an error but cannot fix the error, the packet must be resent.

• Error correction schemes (which are distinct) attempt to pinpoint the flipped bit.

Page 8: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 8

Parity

• Parity is a simple error detection scheme.

• One chooses ahead of time on the type of parity to be used (even or odd). Let us assume even.

• Then one takes a string of binary data and calculates whether the number of 1’s in the string is even or odd.

Page 9: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 9

Parity (Cont.)• The transmitter includes an extra bit

– 0 if the number of data-bit 1’s is even – 1 if the number of data-bits 1’s is odd

• The string consisting of the data plus parity bit is now guaranteed to have an even number of 1’s.

• When the data is going to be used or received in the case of transmission, one checks that the data plus parity bit have even parity (an even number of 1’s).

• If the data now has odd parity, some error must have occurred. – But we do not know which bit was flipped.

Page 10: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 10

Even Parity (Cont.)

D D D D D D D D P

0 0 0 1 1 1 0 0 1

0 0 1 0 1 0 0 0 0

0 1 0 1 1 1 0 0 ?

1 1 1 1 0 0 0 1 ?

D – data P – parity

Page 11: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 11

Parity (Cont.)

• (You may read that the number of 1’s is counted, this is not true and is unnecessary complicated.)

• A multi-input XOR (excluded OR) gate will determine the parity bit, this circuitry is much simpler than what is required for counting the number of 1’s.

Page 12: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 12

2-input XOR Truth Table

A B Output

0 0 0

0 1 1

1 0 1

1 1 0

Page 13: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 13

3-input XOR Truth TableA B C Output

0 0 0 0

0 0 1 1

0 1 0 1

0 1 1 0

1 0 0 1

1 0 1 0

1 1 0 0

1 1 1 1

Page 14: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 14

Parity (Cont.)

• Parity can be used when data is moved around within computers as well as when data is sent from computer to computer.

• Modems use parity. Users may also select no parity, meaning that the modems will not include the parity bit. Sending fewer bits speeds up transmission.

Page 15: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 15

Parity Setting for Modem

Page 16: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 16

Choose the Modems Tab and then the Properties button

Page 17: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 17

Choose the Advanced Tab and click the

Change Default Preferences button

Page 18: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 18

Choose the Advanced Tab

Page 19: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 19

Modem Parity Choices

Page 20: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 20

Checksum• A checksum is another error-detection scheme often used

in transmission.

• The transmission string of data bits is broken up into units, for instance consisting of 16 bits each.

• These 16-bit numbers are then added.

• The sum is sent along as part of the frame’s trailer field.

• The receiver repeats the calculation. If the sums match, it's assumed that no transmission error occurred.

Page 21: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 21

Checksum (Cont.)

• Actually instead of including the sum in the trailer, one can transmit instead its negative.

• The receiver then repeats the sum over the data and includes in that summation the negative of the sum sent in the trailer.

• The result should be zero. It is easier to test for a result of all zeros.

Page 22: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 22

Catching errors

• Since the 16-bit string might end up in any of 216 (65536) possible states, you might assume that the checksum would catch errors 65535/65536 99.9985% of the time.

• But this would assume that all possible errors are equally likely, which is not true.

Page 23: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 23

IP Datagram Protocol

Page 24: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 24

TCP Segment Protocol

Page 25: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 25

Burst errors

• For multi-bit errors, it is more likely that a group of consecutive bits are affected as opposed to randomly selected bits, such an error is known as a burst error.

• It is also common for periodic errors to occur (e.g. the first two bits in every byte).

Page 26: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 26

CRC

• Cyclic Redundancy Check is better at catching burst errors than checksums.

• The idea is the same, perform some mathematical operation on the data, send the result, have the receiver do the same calculation and check that the same answer is obtained.

Page 27: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 27

CRC (Cont.)

• CRC is somewhat like division – If one thinks of the data as a large number, one

can divide it by another number N giving a whole number answer and a remainder

– The remainder could be any number between 0 and N-1.

– The problem here is that division is a fairly difficult computation (more circuitry and a slow process).

Page 28: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 28

CRC (Cont.)

• CRC uses a variation on division that while mathematically abstract is very simple to build a circuit for.

• The circuitry needs only a shift register and some (2-input) XOR gates.

Page 29: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 29

Shift Register

• A register is a small piece of memory that holds values.

• In addition to holding values, a shift register performs a simple operation on the values; it moves them to the left to to the right.

Page 30: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 30

Shift Register

0 1 0 1 0 1 1 1

1 0 1 0 1 1 1 0

0 1 0 1 1 1 0 1

1 0 1 1 1 0 1 0

InputOutput Shift register

time

Page 31: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 31

How shift registers are used?

• Multiplication

• Adding floats

• Converting Parallel Data (the form inside the computer) to Serial (the form sent over transmission lines)

• Cyclic Redundancy check (CRC)

Page 32: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 32

CRC (Cont.)

• Again the 16-bit string might end up in any of 216 (65536) possible states, so you might expect that CRC would catch errors 65535/65536 99.9985% of the time same as a 16-bit checksum.

• But CRC is better at detecting burst errors which are more likely than purely random errors.

• The positions of the XORs are important in determining what kinds of burst errors are detected.

Page 33: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 33

CRC: Transmission Only

• The data must be serialized for a Cyclic Redundancy Check.

• This is fine for transmission error checking since the data was serialized for transmission.

• However, serializing the data would waste a lot of time if the data were in a parallel form (as it is inside the computer).

Page 34: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 34

CRC = Shift register + XORs

Basically one has a shift register with a few excluded OR gates inserted in strategic positions.

Page 35: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 35

Ethernet Frame Protocol

Ethernet uses CRC because at that low level the data is serialized. The higher levels in the stack (e.g. IP and TCP) used checksums.

Page 36: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 36

XOR Truth Table Reminder in CRC Context

Leftmost Bit Newer Bit Result

0 0 0same as newer

bit

0 1 1same as newer

bit

1 0 1opposite of newer bit

1 1 0opposite of newer bit

Page 37: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 37

0 0 0 0 11000001010

0 0 0 1 1000001010

0 0 1 1 000001010

0 1 1 0 00001010

Page 38: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 38

1 1 0 0

0 0 0 1

0001010

001010

0 0 1 0 01010

0 1 0 0 1010

Page 39: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 39

1 0 0 1 010

1 0 1 1 10

1 1 1 0 0

0 1 0 1

Page 40: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 40

Hamming Code

• Hamming code extends the idea of parity. It can be used as either as – An extended error detection scheme

• Parity will discover if an odd number of bits have been flipped. Hamming code can be used to detect two-bit errors.

– An error correction scheme • If a single bit error is assumed, Hamming code can

locate the offending bit.

Page 41: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 41

Hamming code (Cont.)

• Hamming code breaks the bit string into a few overlapping groups. – By overlapping here we mean that a given bit can

belong to more than one group. But each bit should belong to a unique set of groups. That’s how the bit is located.

• One generates a parity bit for each group. – On checking for errors, one identifies which groups

violate parity. From these one can locate the bit in error.

Page 42: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 42

Hamming code (Cont.)

• The set of data and parity bits are numbered such that the parity bits correspond to numbers which are powers of 2: 1, 2, 4, 8 etc. – Recall in binary the powers of 2 consist of one 1 and

the rest 0’s. • 1: 0001

• 2: 0010

• 4: 0100

• 8: 1000

Page 43: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 43

Hamming code (Cont.)

• The groups:– Any bit whose count in binary has a 1 in the 1’s

position belongs to the first group. – Any bit whose count in binary has a 1 in the 2’s

position belongs to the second group. – Any bit whose count in binary has a 1 in the 4’s

position belongs to the third group.– Etc.

Page 44: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 44

Groups for Hamming code

Parity bits

Data bits

Page 45: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 45

Groups for Hamming code

Page 46: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 46

Locating the offending bit

• Let us assume that in a case having four data bits and three parity bits that parity errors were found in check groups 1 and 3.

• We look for the bit that belongs to groups 1 and 3 and does not belong to group 2. – If it belongs to group 1, it has a 1 in the 1’s position. – If it does not belong to group 2, it has a 0 in the 2’s

position. – If it belongs to group 3, it has a 1 in the 4’s position. – It must be 5.

Page 47: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 47

Locating the offending bit

101 5

Page 48: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 48

Page 49: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 49

Page 50: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 50

Neither row violates even parity for the first group.

Page 51: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 51

Both rows have parity violations for group 2.

Neither row has a parity violation for group 3.

Page 52: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 52

Both rows have parity violations in group 4.

If there are parity violations in groups two and four then the binary number identifying the offending bit is 1010 (for both rows, unfortunate example) which is the 10th bit.

Page 53: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 53

Big-endian/Little-endian

• In memory, one addresses bytes. Often the data being written to memory involves more than one byte.

• Big-endian and Little-endian refer to the two different ways in which bytes are placed in memory when the word being written consists of more than one byte.

Page 54: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 54

Big-endian/Little-endian

• In big-endian architectures, the more significant bytes are placed in the locations with the lower addresses.– “Big end first” – Many mainframe computers, particularly IBM

• In little-endian architectures, the less significant bytes are placed in the locations with the higher addresses. – “Little end first”– Most modern computers, including PCs

• The PowerPC is bi-endian because it can understands both ways.

Page 55: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 55

12345678 in Big-endian

More significant Lower address

“Big end first”

Page 56: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 56

12345678 in Little-endian

Less significant Lower address

“Little end first”

Page 57: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 57

Byte versus bit

• Note that the previous example shows only big- and little-endian byte orders.

• One can also consider the bit ordering within each byte. It can also be either big- or little-endian.

• Some architectures use a mix: big-endian ordering for bits and little-endian ordering for bytes, or vice versa.

Page 58: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 58

Origin of the term

• “The terms big-endian and little-endian are derived from the Lilliputians of Gulliver's Travels, whose major political issue was whether soft-boiled eggs should be opened on the big side or the little side. Likewise, the big-/little-endian computer debate has much more to do with political issues than technological merits.”– www.webopedia.com

Page 59: CSC 370 (Blum)1 A few more things about binary numbers

CSC 370 (Blum) 59

Other references

• http://www.webopedia.com

• http://www.whatis.com

• Understanding Data Communications & Networks, William Shay

• http://www.cs.utsa.edu/~wagner/laws/hamming.html