The Hexadecimal Number System and Memory Addressing

Transcription

1 APPENDIX C The Hexadecimal Number System and Memory Addressing U nderstanding the number system and the coding system that computers use to store data and communicate with each other is fundamental to understanding how computers work. Early attempts to invent an electronic computing device met with disappointing results as long as inventors tried to use the decimal number system, with the digits 0 9. Then John Atanasoff proposed using a coding system that expressed everything in terms of different sequences of only two numerals: one represented by the presence of a charge and one represented by the absence of a charge. The numbering system that can be supported by the expression of only two numerals is called base 2, or binary; it was invented by Ada Lovelace many years before, using the numerals 0 and 1. Under Atanasoff s design, all numbers and other characters would be converted to this binary number system, and all storage, comparisons, and arithmetic would be done using it. Even today, this is one of the basic principles of computers. Every character or number entered into a computer is first converted into a series of 0s and 1s. Many coding schemes and techniques have been invented to manipulate these 0s and 1s, called bits for binary digits. The most widespread binary coding scheme for microcomputers, which is recognized as the microcomputer standard, is called ASCII (American Standard Code for Information Interchange). (Appendix B lists the binary code for the basic 127- character set.) In ASCII, each character is assigned an 8-bit code called a byte. The byte has become the universal single unit of data storage in computers everywhere. Table C-1 lists common terms used in the discussion of how numbers are stored in computers. Term Definition Bit A numeral in the binary number system: a 0 or a 1. Byte Kilobyte Megabyte 8 bits bytes, which is 2 to the 10th power, often rounded to 1000 bytes. Either 1024 kilobytes or 1000 kilobytes, depending on what has come to be standard practice in different situations. For example, when calculating floppy disk capacities, 1 megabyte = 1000 kilobytes; when calculating hard drive capacity, traditionally, 1 megabyte = 1024 kilobytes. Table C-1 (continued) 1107

2 1108 APPENDIX C The Hexadecimal Number System and Memory Addressing Term Gigabyte ASCII Hex Definition 1000 megabytes or 1024 megabytes, depending on what has come to be standard practice in different situations. American Standard Code for Information Interchange coding scheme used for microcomputers, which assigns a 7- or 8-bit code to all characters and symbols. See Appendix B for more information. Short for hexadecimal. A number system based on 16 values (called base 16), which is explained in this appendix. Uses the 16 numerals 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. Hex numbers are often followed by a lowercase h to indicate they are in hex (example: 78h). Table C-1 Computer terminology Computers convert binary data into the hexadecimal (hex) number system because it is much less complex than converting data into decimal numbers, and it is much easier for human beings to read hex numbers than to read binary numbers. This way, even though the actual processing and inner workings of computers use the binary system, they often display information using the hex system. Learning to Think Hex One skill a knowledgeable computer support person must have is the ability to read hex numbers and convert hex to decimal and decimal to hex. Once you understand one numbering system (decimal), you can understand any numbering system (including binary and hexadecimal), because they all operate on the same basic principle: place value. So we begin there. Place Value A key to understanding place value is to think of a number system as a method of grouping multiple small units together until there are enough of them to be packed into a single larger group, then grouping multiple larger groups together until there are enough of them to form an even larger group, and so on. In our (decimal) number system, once there are 10 units of any group, that group becomes a single unit of the next larger group. So, groups of 10 units are packed into groups of tens; groups of 10 tens are packed into groups of hundreds; groups of 10 hundreds are packed into groups of thousands, and so forth. An easy way to understand number systems is to think of the numbers as being packaged for shipping, into boxes, cartons, crates, truckloads, and so on. For the decimal numbering system, consider packing widgets (units) into boxes (tens), which

3 Appendix C 1109 are packed into cartons (100s), which are packed into crates (1000s), and so forth. The same analogy works for binary, hexadecimal, and all other number systems. Our friend Joe, in Figure C-1, is a widget packer in the shipping department of the ACE Widget Co. Joe can ship single widgets, or he can pack them in boxes, cartons, crates, and truckloads. He can fit three, and only three, widgets to a box; only three boxes into one carton (3 3 = 9 widgets); only three cartons into one crate (3 9 = 27 widgets); and only three crates into one truck (3 27 = 81 widgets). He is not allowed to pack more widgets into boxes, cartons, crates, or truckloads than those specified. Neither is he allowed to send out a box, carton, crate, or truckload that is not completely filled. C Figure C-1 1 truckload holds 3 crates (81 widgets) 1 crate holds 3 cartons (27 widgets) 1 carton holds 3 boxes (9 widgets) 1 box holds 3 widgets single widgets Joe in the shipping department groups widgets in singles, boxes, cartons, crates, and truc kloads all in groups of three Joe receives an order to ship out 197 widgets. How does he ship them? The answer is shown in Figure C-2. Joe sends out 197 widgets grouped into 2 truckloads (2 81 = 162 widgets), 1 crate (27 widgets), no cartons, 2 boxes (2 3 = 6 widgets), and 2 single widgets. We can write this grouping of widgets as 21022, where the place values from left to right are truckloads, crates, cartons, boxes, and units, which in this case are (in decimal) 162 widgets, 27 widgets, 0 widgets, 6 widgets, and 2 widgets. Notice that each place value in our widget-packing system is a multiple of 3, because the widgets are grouped into three before they are packed into boxes; the boxes are grouped into three before they are packed into cartons, and so on. By grouping the widgets into groups of 3s in this manner, we converted the decimal number (base 10) 197 into the ternary number (base 3) Joe s widget-packing method is a base three, or ternary, system. The numerals in the ternary number system are 0, 1, and 2. When you get to the next value after 2, instead of counting on up to 3, you move one place value to the left and begin again with 1 in that position, which represents 3. So, counting in base 3 goes like this: 0, 1, 2, 10, 11, 12, 20, 21, 22, 100, 101, and so on. This is the same as Joe s never shipping out three of any one group unless they are packed together into one larger group. For example, Joe wouldn t ship three individual boxes, he would ship one carton.

4 1110 APPENDIX C The Hexadecimal Number System and Memory Addressing Figure C-2 2 trucks 1 crate 0 cartons 2 boxes 2 singles Joe s shipment of 197 widgets: 2 truckloads, 1 crate, 0 cartons, 2 boxes, and a group of 2 singles You can easily apply the widget-packing analogy to another base. If Joe used 10 instead of three, he would be using base 10 (decimal) rules. So, numbering systems differ by the different numbers of units they group together. In the hex number system, we group by 16. So, if Joe were shipping in groups of 16, as in Figure C-3, single widgets could be shipped out up to 15, but 16 widgets would make one box. Sixteen boxes would make one carton, which would contain 16 16, or 256, widgets. Sixteen cartons would make one crate, which would contain , or 4096, widgets. Suppose Joe receives an order for 197 widgets to be packed in groups of 16. He will not be able to fill a carton (256 widgets), so he ships out 12 boxes (16 widgets each) and five single widgets: = 192, and = 197 Figure C-3 1 truckload holds 16 crates (65,536 widgets) 1 crate holds 16 cartons (4,096 widgets) 1 carton holds 16 boxes (256 widgets) 1 box holds 16 widgets Widgets displayed in truckloads, crates, cartons, boxes, and singles grouped in 16s single widgets

5 Appendix C 1111 You approach an obstacle if you attempt to write the number in hex. How are you going to express 12 boxes and 5 singles? In hex, you need single numerals to represent the numbers 10, 11, 12, 13, 14, and 15 in decimal. Hex uses the letters A through F for the numbers 10 through 15. Table C-2 shows values expressed in the decimal, hex, and binary numbering systems. In the second column in Table C-2, you are counting in the hex number system. For example, 12 is represented with a C. So you say that Joe packs C boxes and 5 singles. The hex number for decimal 197 is C5 (see Figure C-4). C Figure C-4 Hex C5 represented as C boxes and 5 singles = 197 decimal Decimal Hex Binary Decimal Hex Binary Decimal Hex Binary E C F D E F A B Table C-2 (continued)

6 1112 APPENDIX C The Hexadecimal Number System and Memory Addressing Decimal Hex Binary Decimal Hex Binary Decimal Hex Binary 12 C A D B Table C-2 Decimal, hex, and binary values For a little practice, calculate the hex values of the decimal values 14, 259, 75, and 1024 and the decimal values of FFh and A11h. How Exponents Are Used to Express Place Value If you are comfortable with using exponents, you know that writing numbers raised to a power is the same as multiplying that number by itself the power number of times. For example, 3 4 = = 81. Using exponents in expressing numbers can also help us easily see place value, because the place value for each place is really the base number multiplied by itself a number of times, based on the place value position. For instance, look back at Figure C-1. A truckload is really , or 81, units, which can be written as 3 4. A crate is really 3 3 3, or 27, units. The numbers in Figure C-1 can therefore be written like this: Truckload = 3 4 Crate = 3 3 Carton = 3 2 Box = 3 1 Single = 3 0 (Any number raised to the 0 power equals 1.) Therefore, we can express the numbers in Figure C-2 as multiples of truckloads, crates, cartons, boxes, and singles like this: Truckloads Crates Cartons Boxes Singles (base 3) Decimal equivalent When we sum up the numbers in the last row above, we get 197. We just converted a base 3 number (21022) to a base 10 number (197). Binary Number System It was stated earlier that it is easier for computers to convert from binary to hex or from hex to binary than to convert between binary and decimal. Let s see just how easy. Recall that the binary number system only has two numerals, or bits: 0 and 1. If our friend Joe in shipping operated a binary shipping system, he would pack like this: 2 widgets in a box, 2 boxes in one carton (4 widgets), two cartons in one crate (8 widgets), and two crates in one truckload (16 widgets). In Figure C-5, Joe is asked

7 Appendix C 1113 to pack 13 widgets. He packs 1 crate (8 widgets), 1 carton (4 widgets), no boxes, and 1 single. The number 13 in binary is 1101: (1 2 3 ) + (1 2 2 ) + (0 2 1 ) + (1 2 0 ) = = 13 C Figure C-5 1 crate 1 carton 0 boxes 1 single Binary 1101 = 13 displayed as crates, cartons, boxes, and singles Now let s see how to convert binary to hex and back again. The largest 4-bit number in binary is This number in decimal and hex is: binary 1111 = 1 group of 8 = 8 1 group of 4 = 4 1 group of 2 = 2 1 single = 1 TOTAL = 15 (decimal) Therefore, 1111 (binary) = 15 (decimal) = F (hex) This last calculation is very important when working with computers: F is the largest numeral in the hex number system and it only takes 4 bits to write this largest hex numeral: F (hex) = 1111 (binary). So, every hex numeral (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F) can be converted into a 4-bit binary number. Look back at the first 16 entries in Table C-2 for these binary values. Add leading zeroes to the binary numbers as necessary. When converting from hex to binary, take each hex numeral and convert it to a 4-bit binary number, and string all the 4-bit groups together. Fortunately, when working with computers, you will almost never work with more than two hex numerals at a time. Here are some examples: 1. To convert hex F8 to binary, do the following: F = 1111, and 8 = Therefore, F8 = (usually written ). 2. To convert hex 9A to binary, do the following: 9 = 1001, and A = Therefore, 9A =

8 1114 APPENDIX C The Hexadecimal Number System and Memory Addressing Now try converting from binary to hex: 1. To convert binary to hex, first group the bits in groups of 4, starting at the right and moving left, adding leading zeros as necessary: Then convert each group of 4 bits in binary to a single hex numeral: 0010 = 2, and 1110 = E. The hex number is 2E. Writing Conventions Sometimes when you are dealing with hex, binary, and decimal numbers, it is not always clear which number system is being used. If you see a letter in the number, you know the number is a hex number. Binary numbers are usually written in groups of four bits. Sometimes a hex number is preceded by 0x, as in 0 FF. This book follows the convention of placing a lowercase h after a hex number, like this: 2Eh. Memory Addressing Computers often display memory addresses in the hex number system. You must either think in hex or convert to decimal. It s really easier, with a little practice, to think in hex. Here s the way it works: Memory addresses are displayed as two hex numbers. An example is C800:5. The part to the left of the colon (C800) is called the segment address, and the part to the right of the colon (5) is called the offset. The offset value can have as many as four hex digits. The actual memory address is calculated by adding a zero to the right of the segment address and adding the offset value, like this: C800:5 = C = C8005. The first 640K of Windows 9x or DOS memory is called conventional memory. Look at how that memory is addressed, first in decimal and then in hex (assuming 1 kilobyte = 1024 bytes): 640K = = 655,360 There are 655,360 memory addresses in conventional memory, where each memory address can hold 1 byte, or 8 bits, of either data or program instructions. The decimal value 655,360 converted to hex is A0000 (10 164). So, conventional memory addresses begin with 00000h and end with A0000h minus 1h or 9FFFFh. Written in segment-and-offset form, conventional memory addresses range from 0000:0 to 9FFF:F. Recall that upper memory is defined as the memory addresses from 640K to 1024K. The next address after 9FFF:F is the first address of upper memory, which is A0000, and the last address is FFFFF. Written in segment-and-offset terms, upper memory addresses range from A000:0 to FFFF:F. Here is one way to organize the conversion of a large hex value such as FFFFF to decimal (remember F in hex equals 15 in decimal).

9 Appendix C 1115 FFFFF converted to decimal: = 15 1 = = = = = 3, = = 61, = 15 65,536 = 983,040 TOTAL = 1,048,575 C Remember that FFFFF is the last memory address in upper memory. The very next memory address is the first address of extended memory, which is defined as memory above 1 MB. If you add 1 to the number above, you get 1,048,576, which is equal to , which is the definition of 1 megabyte. Displaying Memory with DOS DEBUG In Figure C-6 you see the results of the beginning of upper memory displayed. The DOS DEBUG command displays the contents of memory. Memory addresses are displayed in hex segment-and-offset values. To enter DEBUG, type the following command at the C prompt and press Enter: C:\> DEBUG First address to dump Dump next group of addresses Figure C-6 Memory dump: -d A000:0 You create a memory dump when you tell the system to record the contents of memory to a file or display it on screen; a dump can be useful when troubleshooting. Type the following dump command to display the beginning of upper memory (the hyphen in the command is the DEBUG command prompt) and press Enter: -d A000:0

10 1116 APPENDIX C The Hexadecimal Number System and Memory Addressing Memory is displayed showing 16 bytes on each line. The A area of memory (the beginning of upper memory) is not used unless the computer is using a monochrome monitor or this area is being used as an upper memory block. In Figure C-6, the area contains nothing but continuous 1s in binary or Fs in hex. The ASCII interpretation is on the right side. To view the next group of memory addresses, you can type d at the hyphen and press Enter. DEBUG displays the next 128 addresses. The A and B ranges of upper memory addresses (upper memory addresses that begin with A or B when written in hex) are used for monochrome monitors. The C range contains the video BIOS for a color monitor. Figure C-7 shows the dump of the beginning of the C range. There is more than one way in fact there are many ways to identify the same segment-and-offset value. Try these commands to display the same upper memory addresses: -d C000:0 -d BFF1:00F0 -d BFFF:0010 -d BEEE:1120 First address to dump Figure C-7 Memory dump: -d C000:0 In summary, reading and understanding binary and hex numbers are essential skills for managing computers. All data is stored in binary in a computer and is often displayed in hex. Memory addresses are often displayed in hex segment-and-offset terms. An address in memory can be written in a variety of segment-and-offset values. The actual memory address is calculated by placing one zero to the right side of the segment address and adding the resulting value to the offset value. To exit DEBUG, type q for quit and press Enter at the hyphen prompt.

APPENDIX C THE HEXADECIMAL NUMBER SYSTEM AND MEMORY ADDRESSING Understanding the number system and the coding system that computers use to store data and communicate with each other is fundamental to understanding

Counting in base 10, 2 and 16 1. Binary Numbers A super-important fact: (Nearly all) Computers store all information in the form of binary numbers. Numbers, characters, images, music files --- all of these

10.2 Sign Magnitude Representation Sign Magnitude is straight-forward method for representing both positive and negative integers. It uses the most significant digit of the digit string to indicate the

Lesson 14..Binary, Hex, and Octal 14-1 We will examine four different number systems here, decimal, binary, hexadecimal (hex), and octal. In your study of these number systems it is very important to note

Section.4 Place Value Systems of Numeration in Other Bases Other Bases The Hindu-Arabic system that is used in most of the world today is a positional value system with a base of ten. The simplest reason

Chapter 5 Data Representation Objectives Upon completion of this chapter you will be able to: Describe the binary and hexadecimal number systems, Given a number in one of base 2, 10, or 16, convert that

CHAPTER TWO Numbering Systems Chapter one discussed how computers remember numbers using transistors, tiny devices that act like switches with only two positions, on or off. A single transistor, therefore,

Decimal to Binary Conversion A tool that makes the conversion of decimal values to binary values simple is the following table. The first row is created by counting right to left from one to eight, for

Number Systems and Data Representation CS221 Inside today s computers, data is represented as 1 s and 0 s. These 1 s and 0 s might be stored magnetically on a disk, or as a state in a transistor, core,

NUMBER SYSTEMS D Number Systems Richard E. Haskell Data inside a computer are represented by binary digits or bits. The logical values of these binary digits are denoted by and, while the corresponding

5/29/204 Common Number Systems Number Systems System Base Symbols Used by humans? Used in computers? Decimal 0 0,, 9 Yes No Binary 2 0, No Yes Octal 8 0,, 7 No No Hexadecimal 6 0,, 9, A, B, F No No Number

Computer Studies 0 Syllabus Number Systems (..) Representation of numbers in binary. Conversion between decimal and binary, and between binary and hexadecimal. Use of subscripts, 0 and 6 for bases. The

Unit 2: Number Systems, Codes and Logic Functions Introduction A digital computer manipulates discrete elements of data and that these elements are represented in the binary forms. Operands used for calculations

1 Number Representation and Arithmetic in Various Numeral Systems Computer Organization and Assembly Language Programming 203.8002 Adapted by Yousef Shajrawi, licensed by Huong Nguyen under the Creative

Introduction ToNumber Systems Collected by: Zainab Alkadhem Page 1 of 25 Digital systems have such a prominent role in everyday life that we refer to the present technological period as the digital age.

1 Basic Computing Concepts (4) Data Representations The Binary System The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer. The

Chapter 3 3.1 Decimal System The radix or base of a number system determines the total number of different symbols or digits used by that system. The decimal system has a base of 10 with the digits 0 through

664 Chapter 23 Binary, Hexadecimal, Octal, and BCD Numbers 23 The Binary Number System Binary Numbers A binary number is a sequence of the digits 0 and, such as 000 The number shown has no fractional part

Slide 1/40 Learning Objectives In this chapter you will learn about: Non-positional number system Positional number system Decimal number system Binary number system Octal number system Hexadecimal number

NORTHWESTERN UNIVERSITY TECHNOLOGICAL INSTITUTE ECE 270 Experiment #9 MICROPROCESSORS PRELAB 1. Fill in the Hex Code and Comment in the table for Experiment C. 2. Fill in the Hex Code and Comment in the

Memory Structure Memory is implemented as an array of electronic switches Each switch can be in one of two states 0 or 1, on or off, true or false, purple or gold, sitting or standing BInary digits (bits)

CHAPTER 3 Number System and Codes 3.1 Introduction On hearing the word number, we immediately think of familiar decimal number system with its 10 digits; 0,1, 2,3,4,5,6, 7, 8 and 9. these numbers are called

Chapter II Binary Data Representation The atomic unit of data in computer systems is the bit, which is actually an acronym that stands for BInary digit. It can hold only 2 values or states: 0 or 1, true

Binary Numbers X. Zhang Fordham Univ. 1 Numeral System! A way for expressing numbers, using symbols in a consistent manner.!! "11" can be interpreted differently:!! in the binary symbol: three!! in the

23CH_PHCalter_TMSETE_949118 23/2/2007 1:37 PM Page 1 Binary, Hexadecimal, Octal, and BCD Numbers OBJECTIVES When you have completed this chapter, you should be able to: Convert between binary and decimal

Arithmetic Circuits Addition, Subtraction, & Multiplication The adder is another classic design example which we are obliged look at. Simple decimal arithmetic is something which we rarely give a second

Chapter 2 Encoding Text with a Small Alphabet Given the nature of the Internet, we can break the process of understanding how information is transmitted into two components. First, we have to figure out

Chapter 3 Data Representation in Computers After studying this chapter the student will be able to: *Learn about binary, octal, decimal and hexadecimal number systems *Learn conversions between two different

Bits, Bytes, and Codes Telecommunications 1 Peter Mathys Black and White Image Suppose we want to draw a B&W image on a computer screen. We first subdivide the screen into small rectangles or squares called

Bits, Data Types, and Operations University of Texas at Austin CS3H - Computer Organization Spring 2 Don Fussell How do we represent data in a computer? At the lowest level, a computer is an electronic

Chapter The Binary Number System. Why Binary? The number system that you are familiar with, that you use every day, is the decimal number system, also commonly referred to as the base-0 system. When you

What is Binary? What is Hex? Mark Terjeson Russell, Tacoma, WA ABSTRACT If anyone is interested in what a megabyte is or how it got to be that way, what number bases are, what binary or hex means, or how

Computer Science 281 Binary and Hexadecimal Review 1 The Binary Number System Computers store everything, both instructions and data, by using many, many transistors, each of which can be in one of two

Two s Complement Arithmetic We now address the issue of representing integers as binary strings in a computer. There are four formats that have been used in the past; only one is of interest to us. The

Why Study Data Representation? Computers process and store information in binary format For many aspects of programming and networking, the details of data representation must be understood C Programming

Number Representation Number System :: The Basics We are accustomed to using the so-called decimal number system Ten digits ::,,,3,4,5,6,7,8,9 Every digit position has a weight which is a power of Base

Binary Numbers In computer science we deal almost exclusively with binary numbers. it will be very helpful to memorize some binary constants and their decimal and English equivalents. By English equivalents

Numeration systems This worksheet and all related files are licensed under the Creative Commons Attribution License, version 1.0. To view a copy of this license, visit http://creativecommons.org/licenses/by/1.0/,

Chapter NO.4 Storage Devices 4.01 Complete the following statements. i) A byte is a group of bits. ii) is a volatile memory. iii) Storage capacity of a sector on floppy is a multiple of bytes. iv) SIMMs

COMP 1113 Sessions 1, 2 and 3 Number Systems The goal of these three class sessions is to examine ways in which numerical and text information can be both stored in computer memory and how numerical information

Number Systems When we type some letters or words, the computer translates them in numbers as computers can understand only numbers. A computer can understand positional number system where there are only

A programmable logical controller uses the binary system rather than the decimal system to process memory cells, inputs, outputs, timers, flags etc.. DECIMAL SYSTEM In order to understand the binary number

Number System When we type some letters or words, the computer translates them in numbers as computers can understand only numbers. A computer can understand positional number system where there are only

Binary and Hex How to count like a computer 2010, Robert K. Moniot 1 Why Binary? The basic unit of storage in a computer is the bit (binary digit), which can have one of just two values: 0 or 1. This is

Page 1 of 5 Unsigned Conversions from Decimal or to Decimal and other Number Systems In all digital design, analysis, troubleshooting, and repair you will be working with binary numbers (or base 2). It

Formatting Variables in C-Max 2.0 One of the many new features in C-Max 2.0 is the enhanced formatting now available for variables. This new capability is available in two distinct areas of variable usage:

CS1Ah Lecture Note 5 Java Expressions Many Java statements can contain expressions, which are program phrases that tell how to compute a data value. Expressions can involve arithmetic calculation and method