33
Memory Terminology & Data Representation CSCI 1060 Fall 2006

Memory Terminology & Data Representation CSCI 1060 Fall 2006

Embed Size (px)

Citation preview

Page 1: Memory Terminology & Data Representation CSCI 1060 Fall 2006

Memory Terminology &Data Representation

CSCI 1060Fall 2006

Page 2: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 2

Outline• Memory Terminology• Instruction/Data Representation

– Decimal Base– Binary to Decimal– Decimal to Binary– Hexadecimal to Decimal– Decimal to Hexadecimal– Hexadecimal to Binary

• ASCII Codes

Page 3: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 3

Outline• Memory Terminology• Instruction/Data Representation

– Decimal Base– Binary to Decimal– Decimal to Binary– Hexadecimal to Decimal– Decimal to Hexadecimal– Hexadecimal to Binary

• ASCII Codes

Page 4: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 4

Memory Terminology• Memory is comprised of sequences of

binary digits — bits • Smallest measure of memory, two

values, 0 or 1 (off or on)• Four bits is a nibble• Eight bits is a byte — can represent a

single character• ASCII code – American Standard Code

for Information Interchange

Page 5: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 5

Memory Terminology• 1 kilobyte = 210 bytes, not 1,000 bytes• 1 megabyte = 220 bytes (1,048,576

bytes)• 1 gigabyte = 230 bytes• 1 terabyte = 240 bytes• 1 petabyte = 250 bytes• … and so on, See Figure 2• B, KB, MB, GB represent bytes• b, kb, mb, gb represent bits

Page 6: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 6

Memory TerminologyHow many bytes are in 4 megabytes?• 1 megabyte = 220 bytes = 1,048,576

bytes• 4 megabytes = 4 * 220 bytes = 4,194,304

bytesHow many bytes are in 2 gigabytes?• 1 gigabyte = 230 bytes = 1,073,741,824

bytes• 2 gigabytes = 2 * 230 bytes =

2,147,483,648 bytes

Page 7: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 7

Memory TerminologyHow many bits are there in 32 kilobytes?• 1 byte = 8 bits• 32 kilobytes = 32 * 210 * 8 bits =

262,144 bitsHow many nibbles in 1 kilobyte?• 1 nibble = 4 bits, 1 byte = 8 bits• 1 kilobyte = 210 bytes * 8 bits / 4 bits =

2,048 nibbles

Page 8: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 8

Outline• Memory Terminology• Instruction/Data Representation

– Decimal Base– Binary to Decimal– Decimal to Binary– Hexadecimal to Decimal– Decimal to Hexadecimal– Hexadecimal to Binary

• ASCII Codes

Page 9: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 9

Outline• Memory Terminology• Instruction/Data Representation

– Decimal Base– Binary to Decimal– Decimal to Binary– Hexadecimal to Decimal– Decimal to Hexadecimal– Hexadecimal to Binary

• ASCII Codes

Page 10: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 10

Instruction/Data Representation

Decimal Base• Decimal numbers are in base 10• Digits are 0-9• Increment the next space to the left

when each slot is “full”• Can expand a number like 536:

– 5*102 + 3*101 + 6*100 = 5*100 + 3*10 + 6*1 = 536

• Other number systems work exactly the same way

Page 11: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 11

Outline• Memory Terminology• Instruction/Data Representation

– Decimal Base– Binary to Decimal– Decimal to Binary– Hexadecimal to Decimal– Decimal to Hexadecimal– Hexadecimal to Binary

• ASCII Codes

Page 12: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 12

Instruction/Data Representation

Binary to Decimal• Binary numbers are in base 2• Digits are 0 or 1• Can expand a binary number like 1101

0111:– 1*27 + 1*26 + 0*25 + 1*24 + 0*23 + 1*22 +

1*21 + 1*20 = – 128 + 64 + 0 + 16 + 0 + 4 + 2 + 1 = 215

• Often, people will separate binary numbers into nibbles for readability

Page 13: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 13

Instruction/Data Representation

Convert 0111 to decimal• 0*23 + 1*22 + 1*21 + 1*20 = 4 + 2 + 1 =

7Convert 1100 1100 to decimal• 1*27 + 1*26 + 0*25 + 0*24 + 1*23 + 1*22

+ 0*21 + 0*20 = 128 + 64 + 8 + 4 = 204Convert 1010 0101 to decimal• 1*27 + 0*26 + 1*25 + 0*24 + 0*23 + 1*22

+ 0*21 + 1*20 = 128 + 32 + 4 + 1 = 165

Page 14: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 14

Outline• Memory Terminology• Instruction/Data Representation

– Decimal Base– Binary to Decimal– Decimal to Binary– Hexadecimal to Decimal– Decimal to Hexadecimal– Hexadecimal to Binary

• ASCII Codes

Page 15: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 15

Instruction/Data Representation

Decimal to Binary• Find the powers of two that add up to

the decimal number• Two methods for accomplishing this:

– Brute Force– Algorithmically

• Algorithmically will apply to any number system

Page 16: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 16

Instruction/Data Representation

Decimal to Binary – Brute Force• Find powers of two up to some arbitrary

number, use as a chart (See Figure 3)• Identify the biggest power of two that

will go into the number and then subtract it

• Repeat until you get a difference of 0• List all powers of two as placeholders

and put 1s where any power of two was used

Page 17: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 17

Instruction/Data Representation

Decimal to Binary – Brute Force• Convert 152 from decimal to binary• 152 – 128 = 24 – 16 = 8 – 8 = 0• _ _ _ _ _ _ _ _ • 1 0 0 1 1 0 0 0

Page 18: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 18

Instruction/Data Representation

Decimal to Binary – Brute Force• Convert 201 from decimal to binary• 201 – 128 = 73 – 64 = 9 – 8 = 1 – 1 = 0• _ _ _ _ _ _ _ _ • 1 1 0 0 1 0 0 1

Page 19: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 19

Instruction/Data Representation

Decimal to Binary – Algorithmically• Continually divide the number by two• When you reach 1, divide one more

time• Take the remainder (guaranteed to be

either 1 or 0) and form a string of 1s and 0s

• Reverse the string to get the binary representation

Page 20: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 20

Instruction/Data Representation

Decimal to Binary – Algorithmically • Convert 152 from decimal to binary

– 152 / 2 = 76 r 0– 76/ 2 = 38 r 0– 38 / 2 = 19 r 0– 19 / 2 = 9 r 1– 9 / 2 = 4 r 1– 4 / 2 = 2 r 0– 2 / 2 = 1 r 0– 1 / 2 = 0 r 1

• Read remainders from bottom to top• (152)10 = (1001 1000)2

Page 21: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 21

Instruction/Data Representation

Decimal to Binary – Algorithmically • Convert 201 from decimal to binary

– 201 / 2 = 100 r 1– 100/ 2 = 50 r 0– 50 / 2 = 25 r 0– 25 / 2 = 12 r 1– 12 / 2 = 6 r 0– 6 / 2 = 3 r 0– 3 / 2 = 1 r 1– 1 / 2 = 0 r 1

• Read remainders from bottom to top• (201)10 = (1100 1001)2

Page 22: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 22

Outline• Memory Terminology• Instruction/Data Representation

– Decimal Base– Binary to Decimal– Decimal to Binary– Hexadecimal to Decimal– Decimal to Hexadecimal– Hexadecimal to Binary

• ASCII Codes

Page 23: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 23

Instruction/Data Representation

Hexadecimal to Decimal• Hexadecimal numbers are in base 16• Digits are 0-F (10 = A, 11 = B, etc.)• Can expand a hexadecimal number like

1128:– 1*163 + 1*162 + 2*161 + 8*160 = – 4096 + 256 + 32 + 8 = 4392

• Can expand a hexadecimal number like AF:– A*161 + F*160 = – 160 + 15 = 175

Page 24: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 24

Instruction/Data Representation

Convert 589 to decimal– 5*162 + 8*161 + 9*160 = 1280 + 128 + 8 =

1417

Convert FA8 to decimal– F*162 + A*161 + 8*160 = 3840 + 160 + 8 =

4008

Convert 1531 to decimal– 1*163 + 5*162 + 2*161 + 1*160 = 4096 +

1280 + 48 + 1 = 5425

Page 25: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 25

Outline• Memory Terminology• Instruction/Data Representation

– Decimal Base– Binary to Decimal– Decimal to Binary– Hexadecimal to Decimal– Decimal to Hexadecimal– Hexadecimal to Binary

• ASCII Codes

Page 26: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 26

Instruction/Data Representation

Decimal to Hexadecimal• Continually divide the number by

sixteen• When you reach a number fifteen or

below, stop, that is your last digit (convert if necessary)

• Reverse the string of remainders to get the hexadecimal representation

Page 27: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 27

Instruction/Data Representation

Decimal to Hexadecimal • Convert 152 from decimal to

hexadecimal– 152 / 16 = 9 r 8– 9 / 16 = 0 r 9

• Read remainders from bottom to top

• (152)10 = (98)16

Page 28: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 28

Instruction/Data Representation

Decimal to Hexadecimal• Convert 201 from decimal to

hexadecimal– 201 / 16 = 12 r 9– 12 / 16 = 0 r 12

• Read remainders from bottom to top

• (201)10 = (C9)16

Page 29: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 29

Instruction/Data Representation

Decimal to Hexadecimal• Convert 5645 from decimal to

hexadecimal– 5645 / 16 = 352 r 13– 352 / 16 = 22 r 0– 22 / 16 = 1 r 6– 1 / 16 = 0 r 1

• Read remainders from bottom to top

• (5645)10 = (160D)16

Page 30: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 30

Outline• Memory Terminology• Instruction/Data Representation

– Decimal Base– Binary to Decimal– Decimal to Binary– Hexadecimal to Decimal– Decimal to Hexadecimal– Hexadecimal to Binary

• ASCII Codes

Page 31: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 31

Instruction/Data Representation

Hexadecimal to Binary• Substitute the binary value of each digit• Can use intermediate step of converting

each “slot” to decimal first (Do NOT calculate overall value)

• A8 = 10 8 = 1010 1000• 98 = 9 8 = 1001 1000• C9 = 12 9 = 1100 1001

Page 32: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 32

Outline• Memory Terminology• Instruction/Data Representation

– Decimal Base– Binary to Decimal– Decimal to Binary– Hexadecimal to Decimal– Decimal to Hexadecimal– Hexadecimal to Binary

• ASCII Codes

Page 33: Memory Terminology & Data Representation CSCI 1060 Fall 2006

CSCI 1060 — Fall 2006 — 33

ASCII Codes• American Standard Code for Information

Interchange• Used to represent data• For instance, the letter ‘A’ is a decimal

65, binary value of 0100 0001