38
Announcement!!! • First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try to go over it on Tuesday…. It will cover everything we’ve gone over so far….some intro computers, data types; I/O; if then else; Boolean operators; number systems

Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Embed Size (px)

Citation preview

Page 1: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Announcement!!!

• First exam next Thursday (I’m trying to give you a first exam before the drop date)

I’ll post a sample exam over the weekend and will try to go over it on Tuesday….

It will cover everything we’ve gone over so far….some intro computers, data types; I/O; if then else; Boolean operators; number systems

Page 2: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

A pause……number systems..because I have to…What you need to know …

1. binary number system

2. converting from decimal to binary and binary to decimal

3. Hexadecimal system -- conversion

Page 3: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Why binary

Page 4: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Advantages

• The advantages of binary: – Simple; easy to build.– Unambiguous signals (hence noise immunity).– Flawless copies can be made.– Anything that can be represented with some

sort of pattern can be represented with patterns of bits.

Page 5: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

More advantages

• Since data of all kinds is stored in computer memory (main and secondary) using the same electronic methods, this means that endless perfect copies can be made of any type of data or program.

Page 6: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

In order to understand the binary numbering system lets first look at our decimal system.

• The decimal numbering system consists of the numbers 0 through 9.

0 1 2

3 4

5 6 7

89

10 9

01

• After nine we place a 1 in the tens column and start again with 0. Which gives us 10.

• The decimal system is also known as base 10 because it is based on the 10 numbers 0 – 9.

Page 7: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Binary Numbers have only two digits 0 or 1

Decimal Binary 0 0 1 1 2 10 3 11 4 100 5 101 6 110 7 111

Binary is known as Base 2

Page 8: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Converting binary – decimalAs you can see it would take a lot of time to create charts to represent Binary numbers.

An easier way is to use the powers of 2

27 =128

26 = 64

25 = 32

24 = 16

23 = 8

22 = 4

21 = 2

20 = 1

27 26 25 24 23 22 21 20

128 64 32 16 8 4 2 1

Lets place the above calculations into a chart that will make it easy to convert a binary number to a decimal number.

Page 9: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Converting Decimal to Binary

• Multiply each digit weight by the base power (i.e. 2) at that unit position and add up all the products

Page 10: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Remember how we “really” convert decimal to decimal

125 10 => 5 x 100 = 5

2 x 101 = 20

1 x 102 = 100 --------

Base 125

Page 11: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

27 26 25 24 23 22 21 20

128 64 32 16 8 4 2 1

0 0 1 0 1 0 0 1

1 x 1 = 1

Total = 41

128 x 0 = 0

64 x 0 = 0

32 x 1 = 32

16 x 0 = 0

8 x 1 = 8

4 x 0 = 0

Use the chart to convert the binary number to decimal.

Note: The bit to the far right is the Least Significant Bit (LSB) and will determine if the number is even or odd.

2 x 0 = 0

Page 12: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

27 26 25 24 23 22 21 20

128 64 32 16 8 4 2 1

0 1 1 1 1 1 1 1

1 x 1 = 1

Total = 127

128 x 0 = 0

64 x 1 = 64

32 x 1 = 32

16 x 1 = 16

8 x 1 = 8

4 x 1 = 4

Use the chart to convert the binary number to decimal.

2 x 1 = 2Note: if consecutive bits from the right are all 1’sThen the answer is the next power of 2 minus 1In this case 128 – 1 = 127

Page 13: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

27 26 25 24 23 22 21 20

128 64 32 16 8 4 2 1 1 0 1 1 1 0 1 0

1 x 0 = 0

Total = 186

128 x 1 = 128

64 x 0 = 0

32 x 1 = 32

16 x 1 = 16

8 x 1 = 8

4 x 0 = 0

Take a piece of paper and convert the binary number to decimal.

2 x 1 = 2

Page 14: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Quick exercises

• Convert 1101100 from binary to decimal.

• Convert 101100 from binary to decimal.

• Convert 1110001 from binary to decimal.

Page 15: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

28 27 26 25 24 23 22 21 20 256 128 64 32 16 8 4 2 1

The largest number that can be represented using an 8 bit binary number is 255.

1 1 1 1 1 1 1 1

Remember the rule – if all the digits are 1 then the number is the next power of 2 minus 1256 – 1 = 255

Page 16: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

So….we need something else

Page 17: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Which Digits Are Available in which Bases

17

Base 10 0 1 2 3 4 5 6 7 8 910

Base 2 0 110

10 d

igits

2 di

gits

Base 16 0 1 2 3 4 5 6 7 8 9 A B C D E F10

16 d

igits

Note: Base 16 is also called “Hexadecimal” or “Hex”.

Base 16Cheat Sheet

A16 = 1010

B16 = 1110

C16 = 1210

D16 = 1310

E16 = 1410

F16 = 1510

Add Placeholder

Add Placeholder

Add Placeholder

Page 18: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Hexadecimal Numbers - Example

160 place161 place162 place

3AB16

This subscript denotes that this number is in Base 16 or “Hexadecimal” or “Hex”.

1’s place16’s place256’s place

Note:162 = 256

Page 19: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Hexadecimal Numbers - Example

3AB16

1’s place16’s place256’s place

So this number represents • 3 two-hundred fifty-sixes• 10 sixteens• 11 ones

Base 16Cheat Sheet

A16 = 1010

B16 = 1110

C16 = 1210

D16 = 1310

E16 = 1410

F16 = 1510

Mathematically, this is

(3 x 256) + (10 x 16) + (11 x 1)= 768 + 160 + 11 = 93910

Page 20: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Converting Hex to Decimal – Again we use the technique:

• Multiply each bit by 16 n, where n is the weight (or power) of the bit

• The weight is the position of the bit, starting from 0 on the right

• Add the results

Page 21: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Example

ABC16 => C x 160 = 12 x 1 = 12

B x 161 = 11 x 16 = 176

A x 162 = 10 x 256 = 2560

-------

2748

Page 22: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Exercises

• Convert 3F3 to decimal

• Convert AA1 to decimal

• Convert 11A to decimal

Page 23: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Why Hexadecimal Is Important

What is the largest number you can represent using four binary digits?

_ _ _ _2

1 1 1 1

23 22 21 20

8 4 2 1

====

8 + 4 + 2 + 1 = 1510

… the smallest number?

_ _ _ _ 20 0 0 0

23 22 21 20

0 + 0 + 0 + 0 = 010

What is the largest number you can represent using a single hexadecimal digit?

Base 16Cheat Sheet

A16 = 1010

B16 = 1110

C16 = 1210

D16 = 1310

E16 = 1410

F16 = 1510

_16

F = 1510

… the smallest number?

_16

0 = 010 Note: You can represent the same range of values with a single hexadecimal digit that you can represent using four binary digits!

Page 24: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Why Hexadecimal Is Important

It can take a lot of digits to represent numbers in binary.

Example:5179410 = 11001010010100102

Long strings of digits can be difficult to work with or look at.

Also, being only 1’s and 0’s, it becomes easy to insert or delete a digit when copying by hand.

Page 25: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Converting Decimal to Binary

• Technique– Divide by two, keep track of the remainder– First remainder is bit 0 (LSB, least significant

bit)– Second remainder is bit 1– Etc.

Page 26: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Converting Decimal to Binary

Example:We want to convert 12510 to binary.

125 / 2 = 62 R 1 62 / 2 = 31 R 0 31 / 2 = 15 R 1 15 / 2 = 7 R 1 7 / 2 = 3 R 1 3 / 2 = 1 R 1 1 / 2 = 0 R 1

12510 = 11111012

Page 27: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Exercises

• Convert 33 decimal to Binary.

• Convert 51 decimal to Binary.

• Convert 19 decimal to Binary.

Page 28: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Converting Decimal to HEX

• Technique– Divide by 16, keep track of the remainder– First remainder is bit 0 (LSB, least significant

bit)– Second remainder is bit 1– Etc

Page 29: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Converting Decimal to Hex

Example:We want to convert 12510 to hex.

125 / 16 = 7 R 13 7 / 16 = 0 R 7

12510 = 7D16

Base 16Cheat Sheet

A16 = 1010

B16 = 1110

C16 = 1210

D16 = 1310

E16 = 1410

F16 = 1510

Page 30: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Exercises

• Convert 28 to Hex

• Convert 346 to Hex

• Convert 117 to Hex

Page 31: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Converting Hex to Binary

• Technique– Convert each hexadecimal digit to a 4 bit

equivalent binary representation (chop it into 4 digit representation

Page 32: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Converting Binary Numbers to Hex

Recall the example binary number from the previous slide:11001010010100102

1100 1010 0101 00102

First, split the binary number into groups of four digits, starting with the least significant digit.

Next, convert each group of four binary digits to a single hex digit.

C A 5 2

Base 16Cheat Sheet

A16 = 1010

B16 = 1110

C16 = 1210

D16 = 1310

E16 = 1410

F16 = 1510

Put the single hex digits together in the order in which they were found, and you’re done!

16

Page 33: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Example

1 0 A F

0001 0000 1010 1111

10AF16 = 0001 0000 1010 1111

Page 34: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Exercise

• Convert 1011100 to hex

• Convert AA1 (hex) to binary

Page 35: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Summary

• All programs and data are stored in binary as it maps directly to on/off signals

• Hexadecimal is base 16, every four binary digits can be represented by one Hex digit (Shorthand for computers)

• To convert any number base to decimal– Multiply each digit weight by the base power at that

unit position and add up all the products• To convert decimal to any base(2,16..)

– Keep Dividing the decimal number by the base until you reach zero, keeping the remainders each time. Read from the bottom up.

Page 36: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Problems:

• Convert 101 to binary

• Convert 1234 16 to decimal

• Convert 0000 1010 1011 1100 1101 to hexadecimal

Page 37: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

Real-world problems

• Convert the following MAC address to decimal, keeping a colon between each byte.

fe:fd:00:00:5c:a4

• Convert the following IP address to binary and hexadecimal, keeping a dot between each byte (remember a byte is 8 bits)

131.247.168.48

Page 38: Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try

More real-world problems

• Convert the following subnet mask to binary, keeping a dot between each byte.

255.255.128.0