25
Craig Schock, 2003 Binary Numbers • Numbering Systems • Counting • Symbolic • Bases • Common Bases (10, 2, 8, 16) • Representing Information • Binary to Decimal Conversions • Bit Groupings • Encoding Information

Binary Numbers

  • Upload
    wind

  • View
    28

  • Download
    0

Embed Size (px)

DESCRIPTION

Binary Numbers. Numbering Systems Counting Symbolic Bases Common Bases (10, 2, 8, 16) Representing Information Binary to Decimal Conversions Bit Groupings Encoding Information. Numbering Systems. There are many different ways to represent numbers Counting Based Systems - PowerPoint PPT Presentation

Citation preview

Page 1: Binary Numbers

Craig Schock, 2003

Binary Numbers

• Numbering Systems• Counting• Symbolic

• Bases• Common Bases (10, 2, 8, 16)

• Representing Information • Binary to Decimal Conversions• Bit Groupings• Encoding Information

Page 2: Binary Numbers

Craig Schock, 2003

Numbering Systems

• There are many different ways to represent numbers• Counting Based Systems

• The number is represented by the same number of counters

• Symbolic• Uses symbols to represent values

7 =

Page 3: Binary Numbers

Craig Schock, 2003

Symbolic Numbering Systems

• The symbols within the numbering systems are an “abstraction” of the actual number.

• The symbol represents a value

• Abstraction: A symbolic representation of a thing or idea.

• In order for an abstraction to be useful, people must agree on its meaning.

• Symbols are combined to represent larger numbers

Page 4: Binary Numbers

Craig Schock, 2003

Numbering Bases

• Each symbolic numbering system has a “base”

• Base: The number of symbols in the system

• eg. Decimal has 10 symbols (0-9)

01234

56789

Page 5: Binary Numbers

Craig Schock, 2003

Common Bases

• The most common base used in western society is base 10 (decimal)

• It is based on 10 symbols• Humans have 10 “digits”

• In the computer world, there are other commonly used bases:

• Binary (base 2, 0-1)• Octal (base 8, 0-7)• Hexadecimal (base 16, 0-9, A-F)

Page 6: Binary Numbers

Craig Schock, 2003

Decimal: Representing Numbers

• Because decimal has 10 digits, it can easily represent numbers 0-9.

0 51 62 73 84 9

However, representing numbers which are larger than the number of symbols poses a problem.

Page 7: Binary Numbers

Craig Schock, 2003

Decimal: Positional Notation

• Symbolic systems deal with representing large numbers through a positional notation.

• The actual value of the symbol is based on its position• Multiplication and addition is employed to increase the value• The factor used in the multiplication is the base

7 5 6

x1x10x10x10

=7 x 10 x 10 +5 x 10 +6 x 1

Note: base 10First column starts at “1”

100

101

102

Page 8: Binary Numbers

Craig Schock, 2003

Information

• Information: What is it?

A message received and understood that reduces the recipient’s uncertainty

• “Uncertainty” implies that for information to be present, there must be at least 2 possible outcomes.

• If there was only 1 outcome, there would be no uncertainty.

• If we were to represent information as a numbering system, it would be a system which contained at least 2 symbols.

Page 9: Binary Numbers

Craig Schock, 2003

Representing Information

• We could choose any numbering system to represent information.

• Whatever system we choose, it must contain at least 2 symbols.

• Electrically, it is easy to represent a system containing 2 symbols using switches.

• Off• On

• We can also think of philosophical systems based on “truthness” and “falseness”

Page 10: Binary Numbers

Craig Schock, 2003

Binary – Base 2

• Binary is a numbering system which contains 2 symbols (i.e. base 2)

• For easy interoperability with other bases (such as decimal), we choose the digits “0” and “1” to represent the two possible values

• A “bit” is a single BInary digiT• A bit is the smallest unit of information

• What if the information we need to represent has more than 2 possibilities?

Page 11: Binary Numbers

Craig Schock, 2003

Binary – Positional Notation

• As with decimal, we can represent values which are larger than the number of symbols we have.

• This is accomplished through the use of a positional notation. Because the base is 2, the multiplier for each position is x2

1 1 1

x1x2x2x2

=1 x 2 x 2 +1 x 2 +1 x 1

Note: base 2

20

21

22

Page 12: Binary Numbers

Craig Schock, 2003

Binary to Decimal Conversions

• Because humans work well with decimal, it is useful to know how to convert between binary and decimal:

0000 = 0 1000 = 80001 = 1 1001 = 90010 = 2 1010 = 100011 = 3 1011 = 110100 = 4 1100 = 120101 = 5 1101 = 130110 = 6 1110 = 140111 = 7 1111 = 15

Page 13: Binary Numbers

Craig Schock, 2003

Binary to Decimal Conversions (contd)

1 1 0 1

1248

=

1x128 + 1x16 + 1x8 + 1x4 + 1x1 =128 + 16 + 8 + 4 + 1 = 157

1 1 0 1

1248

1 0 0 1

163264128

=

1x8 + 1x4 + 1x1 =8 + 4 + 1 = 13

To convert to decimal, represent the column values in decimal

Page 14: Binary Numbers

Craig Schock, 2003

How many bits to use?

• In the last few slides, we have seen binary numbers which contain differing numbers of digits – 3 bits, 4 bits, and 8 bits

• How many bits should one use?• That depends on what information one wishes to represent.

• eg. How many bits are necessary to represent the days of the week?

Page 15: Binary Numbers

Craig Schock, 2003

How Many bits?

• Days of the week. Let’s let each bit combination represent one day:

000 = Sunday001 = Monday010 = Tuesday011 = Wednesday100 = Thursday101 = Friday110 = Saturday

• Because there are 7 days of the week, we need enough bits which have at least 7 different combinations. (3 bits)

Page 16: Binary Numbers

Craig Schock, 2003

Bits and Combinations

• How can we tell how many combinations a given number of bits will provide?

• The answer is based on a simple formula:

n bits provides 2 combinationsn

1 bit = 2 combinations2 bits = 4 combinations3 bits = 8 combinations4 bits = 16 combinations5 bits = 32 combinations6 bits = 64 combinations7 bits = 128 combinations8 bits = 256 combinations

9 bits = 512 combinations10 bits = 1024 combinations11 bits = 2048 combinations12 bits = 4096 combinations13 bits = 8192 combinations14 bits = 16384 combinations15 bits = 32768 combinations16 bits = 65536 combinations

Page 17: Binary Numbers

Craig Schock, 2003

More combinations

• How many bits are necessary to represent

• The days of the month?• Your age• The year of your birth?• The number of cars you have owned?• Your salary?• The salary of a CEO of a multinational corporation?• The Canadian national debt?• The US national debt?• The number of atoms in the universe?

Page 18: Binary Numbers

Craig Schock, 2003

Bit groupings

• Relatively speaking, there are few cases where the information content only requires 1 bit.

• Bits are usually grouped into larger units.

• Common groupings include:

4 bits = 1 nybble (not commonly used)8 bits = 1 byte

1024 bytes = 1 kilobyte (or 1K)1024 * 1024 bits = 1048576 bits = 1 megabits = 131072 bytes1024 * 1024 bytes = 1048576 bytes = 1 Megabyte1024 * 1024 * 1024 bytes = 1073741824 bytes = 1 Gigabyte

Page 19: Binary Numbers

Craig Schock, 2003

What does it mean?

• Exercise: What do the following numbers mean?

102, 102, 102, 126, 126, 102, 102, 1020, 24, 24, 0, 24, 24, 24, 2424, 24, 24, 24, 24, 0, 24, 24

Page 20: Binary Numbers

Craig Schock, 2003

What does it mean?

102 = 01100110 0 = 00000000 24 = 00011000102 = 01100110 24 = 00011000 24 = 00011000 102 = 01100110 24 = 00011000 24 = 00011000 126 = 01111110 0 = 00000000 24 = 00011000126 = 01111110 24 = 00011000 24 = 00011000102 = 01100110 24 = 00011000 0 = 00000000102 = 01100110 24 = 00011000 24 = 00011000102 = 01100110 24 = 00011000 24 = 00011000

Page 21: Binary Numbers

Craig Schock, 2003

What does it mean?

11 11 11 11 11 11 11 11 11 11 11 111111 11 111111 11 11 11 11 11 11 11 11 11 11 11 11 11

Page 22: Binary Numbers

Craig Schock, 2003

Information Encoding

• The exercise illustrates and important concept in computer science.

• We have learned that binary numbers can be used to represent information. Information, as a series of bits, can be represented as decimal numbers. The example provided a series of decimal numbers. But what do they mean?

• What the numbers mean is a matter of definition

• Information is encoded using bits• Encoding is an abstraction.

Page 23: Binary Numbers

Craig Schock, 2003

ASCII Codes

• ASCII – American Standard Code for Information Interchange

• ASCII is an 7 bit encoding which is used to represent the Roman alphabet, numbers, standard symbols and printer control characters.

• Some companies expanded ASCII to 8 bits. They used the extra combinations to encode special characters

Page 24: Binary Numbers

Craig Schock, 2003

The ASCII Standard

Dec Char0 NUL1 SOH2 STX3 ETX4 EOT5 ENQ 6 ACK7 BEL8 BS9 HT10 LF11 VT12 FF13 CR14 SO15 SI16 DLE17 DC118 DC219 DC320 DC421 NAK22 SYN

Dec Char23 ETB24 CAN25 EM26 SUB27 ESC28 FS29 GS30 RS31 US32 SPACE33 !34 "35 #36 $37 %38 &39 '40 (41 )42 *43 +44 , 45 -

Dec Char46 .47 /48 049 150 251 352 453 554 655 756 857 958 :59 ;60 <61 =62 >63 ?64 @65 A66 B67 C68 D

Dec Char69 E70 F71 G72 H73 I74 J75 K76 L77 M78 N79 O80 P81 Q82 R83 S84 T85 U86 V87 W88 X89 Y90 Z91 [

Dec Char92 \93 ]94 ^95 _96 `97 a98 b99 c100 d101 e102 f103 g104 h105 i106 j107 k108 l109 m110 n111 o112 p113 q114 r

Dec Char115 s116 t117 u118 v119 w120 x121 y122 z123 {124 |125 }126 ~127 DEL

Page 25: Binary Numbers

Craig Schock, 2003

Using ASCII

• Using the ASCII standard, we can encode an English sentence as a series of ASCII values

I would like to buy some cheese.

73, 32, 119, 111, 117, 108, 100, 32, 108, 105, 107, 101, 32, 116, 111, 32, 98, 117, 121, 32, 115, 111, 109, 101, 32, 99, 104, 101, 101, 115, 101, 46

• How many bytes are needed to encode the above sentence using ASCII?

32 byes