330 likes | 454 Views
Memory Terminology & Data Representation. CSCI 1060 Fall 2006. 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. Outline. Memory Terminology
E N D
Memory Terminology &Data Representation CSCI 1060 Fall 2006
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
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
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
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
Memory Terminology How many bytes are in 4 megabytes? • 1 megabyte = 220 bytes = 1,048,576 bytes • 4 megabytes = 4 * 220 bytes = 4,194,304 bytes How 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
Memory Terminology How many bits are there in 32 kilobytes? • 1 byte = 8 bits • 32 kilobytes = 32 * 210 * 8 bits = 262,144 bits How many nibbles in 1 kilobyte? • 1 nibble = 4 bits, 1 byte = 8 bits • 1 kilobyte = 210 bytes * 8 bits / 4 bits = 2,048 nibbles
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
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
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
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
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
Instruction/Data Representation Convert 0111 to decimal • 0*23 + 1*22 + 1*21 + 1*20 = 4 + 2 + 1 = 7 Convert 1100 1100 to decimal • 1*27 + 1*26 + 0*25 + 0*24 + 1*23 + 1*22 + 0*21 + 0*20 = 128 + 64 + 8 + 4 = 204 Convert 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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