COMP 211: Lecture 6 - Information Encoding, Number Systems, and Integer Representation (and Character Encoding)c

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/77

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

78 Terms

1
New cards

What do humans understand?

Numbers and strings (i.e characters)

2
New cards

What are examples of what humans understand?

100 or the matrix

3
New cards

What do machines understand?

Binary numbers

4
New cards

Do machines understand human language?

No. We have to convert human language into binary representation

5
New cards

What is encoding?

To convert information into a different form.

6
New cards

What is a character example of binary encoding?

‘a’ encoded as binary 01100001_2 number

7
New cards

What is the representation for transforming characters to binary?

ASCII representation

8
New cards

What is a number example of binary encoding?

25_10 encoded as 00011001_2 number

9
New cards

What is the representation for transforming numbers to binary?

Base-2 representation

10
New cards

How many digits do base-10 numbers have?

10; 0-9

11
New cards

What does it mean for a number to be base-10?

Each digit is multiplied by a power of 10

12
New cards

What is the formula for getting to base-10?

v is base-10 value, d is decimal digit, and i is digit position, increasing right to left, starting from 0

13
New cards
  • How do we get 17543_10?

  • How do we get 173_10?

  • How do we get 1025_10?

  • How do we get 2001_10?

Answer

14
New cards

What are base-2 numbers?

Binary numbers

15
New cards

How many digits to base-2 numbers have?

2 binary digits; 0 and 1

16
New cards

What does it mean for a number to be base-2?

Each digit multiplied by power of 2

17
New cards

What is the formula for getting to base-2?

v is base 10 value, b is binary digit, and i is digit position

<p><span>v is base 10 value, b is binary digit, and i is digit position</span></p>
18
New cards

What is the range of binary numbers?

0 - (2^N-1)

N = Number of bits

19
New cards
  • How do we get 011111010000_

  • How do we convert 73_10 to binary?

  • How do we convert 181_10 to binary?

  • How do we convert 213_10 to binary?

  • 2000_10

  • 01001001

  • 10110101

  • 11010101

20
New cards

What are some Base-2 Terminology?

LSB, MSB

21
New cards

What is LSB?

Least significant bit

22
New cards

What is MSB?

Most significant bit

23
New cards

What is considered the least significant bit? What is considered the most significant bit?

The LSB is going to be the lowest power of two, and the MSB is the highest power of 2

24
New cards

What is the goal of a Decimal to Binary Algorithm?

We can apply a more algorithmic approach to converting a base-10 decimal number to binary; inverse problem

25
New cards

What is the Decimal to Binary Algorithm?

knowt flashcard image
26
New cards

Where does the Decimal to Binary Algorithm Apply?

To any other number bases

27
New cards

How do we use the Decimal to Binary Algorithm on other number bases?

for base-n, replace divide by 2 with divide by n

28
New cards
  • Convert 18_10 to binary (base-2)

10010

29
New cards

What are Base-16 numbers also called?

Hexadecimal numbers

30
New cards

How many digits are in hexadecimals?

16 hex digits; 0-9 and A-F

31
New cards

What is a hex digit also called?

Hexit

32
New cards

What is a hexdigit?

A group of 4 binary bits

<p>A group of 4 binary bits</p>
33
New cards

What is each hexit multiplied by?

A power of 16

34
New cards

WHat is the formula for hexits?

v is base-10 value, d is hexit, and i is digit position (increasing right to left, starting at 0)

<p>v is base-10 value, d is hexit, and i is digit position (increasing right to left, starting at 0)</p>
35
New cards
  • 0×7d0

  • Convert 73_10 to Hexadecimal

  • Convert 01101100_2 to Hexadecimal

  • Convert 0xA9 to Binary

0111 1101 0000

0049

6C

1010 1001

36
New cards

What is ASCII?

A standard format with 7 bits encoded to 128 characters

37
New cards

How many characters total in ASCII?

2^7'

38
New cards
  • ‘A’ in base_10, base_2, and base_16

  • ‘0’ in base_10, base_2, and base_16

  • ‘\0’ in base_10, base_2, and base_1

65; 1000001; 0×41

48; 0110000; 0×30

0; 0000000; 0×00

39
New cards

What character has a 0 value?

The null terminator

40
New cards

Why is the null terminator value important?

Because it’s the only character with 0 value, it allows us to null terminate strings (recognizes the end of a string)

41
New cards
  • Convert ‘brent’ to Binary

<p></p>
42
New cards

What is fixed-length encoding?

When all symbols have same number of bits

43
New cards

What is an example of fixed-length encoding?

ASCII; each character always has 7 bits

44
New cards

When is fixed-length encoding used?

When all symbols have equal probability

45
New cards

What is variable-length encoding?

When symbols can use different numbers of bits

46
New cards

What is an example of variable-length encoding?

UNICODE 8 and 16

47
New cards

When is variable-length encoding used?

When some symbols are more likely than others; for example, compression

48
New cards

Variable-length Example

  • Suppose X and Y are twice as likely as W and Z

  • Encoding possibility: X and Y are 1 bit, W and Z are 2 bits

  • X and Y would use less bits, while W and Z require more bits

  • Main concept is commonly occurring symbols are encoded with few bits; the idea behind compression

49
New cards

How do we determine the number of bits for fixed-length representation?

  • Number of symbols = to 2^ number of bits

  • if we had 2 symbols, one bit is needed

  • If we had 4 symbols, 2 bits are needed

  • If we have 2^n symbols, then n bits are needed

    • We take the ceiling of log_2(M) to find number of bits for M symbol==

<ul><li><p>Number of symbols = to 2^ number of bits</p></li><li><p>if we had 2 symbols, one bit is needed</p></li><li><p>If we had 4 symbols, 2 bits are needed</p></li><li><p>If we have 2^n symbols, then n bits are needed</p><ul><li><p>We take the ceiling of log_2(M) to find number of bits for M symbol==</p></li></ul></li></ul>
50
New cards
  • If we had the digits {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, how many bits are need?

  • If we had the 84 english characters (A-Z (26), a-z (26), 0-9 (10), punctuation (8), math (9), financial (5)), how many bits are need?

log[10] = 3.22 → 4

log[84] = 1.92 → 2

51
New cards

What is MSB used for? How?

Used to encode the sign. If MSB = 0_2, then it is a positive binary number. If MSB = 1_2, then it is a negative binary number.

<p>Used to encode the sign. If MSB = 0_2, then it is a positive  binary number. If MSB = 1_2, then it is a negative binary number.</p>
52
New cards

What is the range for Signed Magnitude Representation?

-(2^(N-1) - 1) to (2^(N-1) - 1)
N = # of bits

53
New cards

What is the range represented in?

Base-10

54
New cards

If N = 8 bits, what is the minimum base-10 number that can be represented in signed magnitude? What is the maximum base-10 number

-127 - 127

55
New cards
  1. What is -49 in SMR

  2. What is +49 in SMR

  3. What is +86 in SMR

  4. What is -86 in SMR

10110001

00110001

01010110

11010110

56
New cards

Why is Signed Magnitude Good?

Easy to negate and compute the absolute value.

57
New cards

What is one reason why Signed Magnitude is bad?

Adding and subtracting can become complicated because we would need to implement a first hardware circuit to the add, and a second hard ware circuit to subtract.

58
New cards

What is the second reason why Signed Magnitude is bad?

2 different ways to represent 0. If all the bits are 0 and the MSB is 1, then the number is a -0. If the MSB is 0, then it is +0. Being able to represent 0 in 2 different ways is not ideal because it can complicate hardware design

59
New cards

What is signed representation like in practice?

It is not frequently used for integer numbers, but used in floating point numbers.

60
New cards

What is another signed representation?

2’s Complement Representation.

61
New cards

How is the sign encoded in 2’s Complement?

MSB is used, so 1 = negative sign, and 0 = positive sign. Conversion from base-10 to base-2 is slightly different from standard MSB Signed magnitude.

<p>MSB is used, so 1 = negative sign, and 0 = positive sign. Conversion from base-10 to base-2 is slightly different from standard MSB Signed magnitude.</p>
62
New cards
<p>2’s Complement examples</p>

2’s Complement examples

-42

42

63
New cards

What is another process other than the formula to convert base-10 to base-2 in 2’s Complement?

A two step negating a number and algorithmic approach.

64
New cards

Explain the 2’s complement second approach.

  1. Complement every bit (1_2 → 0_2, 0_2 → 1_2)

  2. Add 1_2 using binary math (see supplement reading assignment)

65
New cards
<p>2’s Complement Example</p>

2’s Complement Example

Answer

<p>Answer </p>
66
New cards
  1. +86 to 2’s Complement

  2. -86 to 2’s Complement

<p></p>
67
New cards

What is 2’s complement’s range?

(-2^(N-1)) to (2^(N-1) - 1)

68
New cards

If N = 8, what is the range in 2‘s complement?

Answer

<p>Answer</p>
69
New cards

What will happen if you apply 2’s complement to a negative number?

You will get a positive number.

70
New cards
<p>Apply 2’s Complement to this negative number.</p>

Apply 2’s Complement to this negative number.

knowt flashcard image
71
New cards

What is another thing we can do in 2’s complement? Why?

Addition, no subtraction. Because we use the MSB to determine whether the number is negative or not, we could do the number + a negative number to perform subtraction.

72
New cards

What is a good thing about representing integers in 2’s Complement?

There is only one 0, no positive or negative 0.

73
New cards

Prove the claim about the 0 in 2’s complement.

Answer

<p>Answer</p>
74
New cards

Signed Magnitude vs 2’s Complement

knowt flashcard image
75
New cards
<p>Sign Extension Example.</p>

Sign Extension Example.

We would pad the MSBs with 0s to make 8. We don’t change the value of the number.

76
New cards

What do we do if we wanted sign extension with a negative binary nmber?

We would need to use 2’s complement, signed magnitude does not work.

<p>We would need to use 2’s complement, signed magnitude does not work.</p>
77
New cards

What is the bad things about 2’s complement?

More complex to negate and compute the absolute value.

78
New cards

What are all the good things about 2’s complement?

2’s complement fixes the issues with signed magnitude. It uses only the add operation, only has one 0, and can use sign extension. Overall, it simplifies hardware design.