Many information systems are operated every day by people who couldn t tell you the

Similar documents
[301] Bits and Memory. Tyler Caraza-Harter

Discussion. Why do we use Base 10?

ITP 140 Mobile App Technologies. Colors

Data Representation 1

1.1 Review of Place Value

1.1 Data representation

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

Memory Addressing, Binary, and Hexadecimal Review

Example 1: Denary = 1. Answer: Binary = (1 * 1) = 1. Example 2: Denary = 3. Answer: Binary = (1 * 1) + (2 * 1) = 3

Dec Hex Bin ORG ; ZERO. Introduction To Computing

FA269 - DIGITAL MEDIA AND CULTURE

CC411: Introduction To Microprocessors

Number Systems MA1S1. Tristan McLoughlin. November 27, 2013

Number Systems Using and Converting Between Decimal, Binary, Octal and Hexadecimal Number Systems

Mathematics. Name: Class: Transforming Life chances

REPRESENTING INFORMATION:

Digital codes. Resources and methods for learning about these subjects (list a few here, in preparation for your research):

Lecture 1: What is a computer?

Excerpt from "Art of Problem Solving Volume 1: the Basics" 2014 AoPS Inc.

1.1 Information representation

Variables and Data Representation

Objectives. Connecting with Computer Science 2

The type of all data used in a C++ program must be specified

Bits and Bytes. Here is a sort of glossary of computer buzzwords you will encounter in computer use:

4 + 4 = = 1 5 x 2 = 10

Bits, Words, and Integers

Binary Representation. Jerry Cain CS 106AJ October 29, 2018 slides courtesy of Eric Roberts

17. [Exploring Numbers]

Topic Notes: Bits and Bytes and Numbers

Binary Systems and Codes

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

Teaching KS3 Computing. Session 3 Theory: More on binary and representing text Practical: Introducing IF

Making Backgrounds With Paint Shop Pro

Topic Notes: Bits and Bytes and Numbers

Using sticks to count was a great idea for its time. And using symbols instead of real sticks was much better.

Data Representation From 0s and 1s to images CPSC 101

Final Labs and Tutors

Computer Number Systems Supplement

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

ADDING CSS TO YOUR HTML DOCUMENT. A FEW CSS VALUES (colour, size and the box model)

Chapter 7. Representing Information Digitally

GENERAL MATH FOR PASSING

Parts are adapted from Windows 98 by Mark Twain Media, Inc. A Computer System has Hardware and Software

Audio Text for the Lesson: Counting Systems

Module 1: Information Representation I -- Number Systems

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. Numbers & Number Systems

Section 1.1 Definitions and Properties

umber Systems bit nibble byte word binary decimal

Mastering Binary Math

DIGITAL SYSTEM FUNDAMENTALS (ECE 421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE 422) COURSE / CODE NUMBER SYSTEM

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

Converting between Percents, Decimals, and Fractions

COPYRIGHTED MATERIAL. An Introduction to Computers That Will Actually Help You in Life. Chapter 1. Memory: Not Exactly 0s and 1s. Memory Organization

Reading 2.2 Cascading Style Sheets

Number System (Different Ways To Say How Many) Fall 2016

SPEED UP YOUR CODING PROCESS HTML INSIGHTS YOU DIDN T KNOW ABOUT. 1

Variables and Literals

Unit 2 Digital Information. Chapter 1 Study Guide

Excerpt from: Stephen H. Unger, The Essence of Logic Circuits, Second Ed., Wiley, 1997

Binary. Hexadecimal BINARY CODED DECIMAL

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

Summer 2013 Modules 9-13

Lecture 1: Digital Systems and Number Systems

Review of HTML. Ch. 1

Intermediate Programming & Design (C++) Notation

Computer Basics. Page 1 of 10. We optimize South Carolina's investment in library and information services.

Lecture C1 Data Representation. Computing and Art : Nature, Power, and Limits CC 3.12: Fall 2007

Chapter 2. Data Representation in Computer Systems

Number Systems II MA1S1. Tristan McLoughlin. November 30, 2013

<body bgcolor=" " fgcolor=" " link=" " vlink=" " alink=" "> These body attributes have now been deprecated, and should not be used in XHTML.

CSS. Lecture 16 COMPSCI 111/111G SS 2018

But I know what most of you will do: use a calculator to convert; that's fine, IF you understand the theory.

Notes from April 3 Tuesday

Real Numbers finite subset real numbers floating point numbers Scientific Notation fixed point numbers

Digital Fundamentals

cast int( x float( x str( x hex( int string int oct( int string int bin( int string int chr( int int ord( ch

Chapter 1 Operations With Numbers

Worksheet - Storing Data

CSS Lecture 16 COMPSCI 111/111G SS 2018

The type of all data used in a C (or C++) program must be specified

Chapter 3 Analyzing Normal Quantitative Data

Part II: Creating Visio Drawings

Lab Using the Windows Calculator with Network Addresses

Section 1.2 Fractions

Math in Focus Vocabulary. Kindergarten

St. Benedict s High School. Computing Science. Software Design & Development. (Part 2 Computer Architecture) National 5

Binary Codes. Dr. Mudathir A. Fagiri

COMP 102: Computers and Computing

Slide Set 1. for ENEL 353 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Number Systems. Dr. Tarek A. Tutunji Philadelphia University, Jordan

CMSC 1513 Lecture 1.2

Fractions and their Equivalent Forms

Analogue vs. Discrete data

Applets and the Graphics class

Appendix D CSS Properties and Values

UNIT 2 NUMBER SYSTEM AND PROGRAMMING LANGUAGES

The Gray Code. Script

User. Application program. Interfaces. Operating system. Hardware

Year Two Inspire Objective Target Sheet UNIT ONE: NUMBERS TO Recognise representations of, read and write, numbers to

Transcription:

CHAPTER 15: NUMBER SYSTEMS You don t have to be a mathematician to have a feel for numbers. John Forbes Nash, Jr. Many information systems are operated every day by people who couldn t tell you the difference between Base-2 and second base. Still, a basic understanding of number systems is more than a sadistic ritual disguised as an interesting mental exercise; it gives insights into how computers operate. NUMBERING SYSTEMS When you look at this image, you may see a bunch of numbers: These numerals are representations of numbers in a given numbering system specifically, in Base-10. A number system gives you the rules for how to represent numbers. Without a numbering system, we would have to have a different symbol for every single number. A number system allows us to write twelve as 12 instead of, say,, or some other odd thing Humans commonly use a number system called Base- 10. Ostensibly, we developed this because we had ten fingers. When we count, it looks like this: 0 zero 1 one 2 two 3 three 4 four 5 five 6 six 7 seven 8 eight 9 nine 10 ten Note that in Base 10, the number ten doesn t have a unique symbol. Instead, when you get to ten, you move 1 to the tens column and place a zero in the ones column. One way to look at this is to say we have 1 ten and 0 ones. Similarly, if we were to continue... 96 ninety-six 97 ninety-seven 98 ninety-eight 99 ninety-nine 100 one hundred When we get to one hundred, we place a one in the hundreds column, a zero in the tens column, and a zero in the ones column. In this way, we are saying we have 1 hundred and 0 tens and 0 ones. Continuing... 996 nine hundred ninety-six 997 nine hundred ninety-seven 998 nine hundred ninety-eight 999 nine hundred ninety-nine 1000 one thousand When we get to one thousand, we are saying we have 1 thousand plus 0 hundreds plus 0 tens plus 0 ones. Let s see if we can organize this idea graphically for 8,925: Thousand Hundred Ten One 8, 9 2 5 x 1 5 x 10 + 20 x 100 + 900 x 1,000 + 8,000 8,925

PAGE 94 CHAPTER 15: NUMBER SYSTEMS WAYNE THOMAS SPIES Thus, 8,925 is 8 thousands plus 9 hundreds plus 2 tens plus 5 ones. At this point, you are either nodding in agreement, or just nodding off. It seems to be a needlessly complicated way of doing something with which we are very, very familiar. This familiarity has hidden an interesting idea, but first we must refresh your math skills. EXPONENTIALS You know that 2 2, which we read as two squared, or two to the second power, means 2 x 2, or 4. The exponent, 2, says how many times the base is multiplied times itself. For example: 2 1 = 2 2 2 = 2 x 2 = 4 2 3 = 2 x 2 x 2 = 8 2 4 = 2 x 2 x 2 x 2 = 16 2 5 = 2 x 2 x 2 x 2 x 2 = 32 2 6 = 2 x 2 x 2 x 2 x 2 x 2 = 64 MULTIPLYING POWERS Staying in review mode, you will remember that: a x x a y (x + y) = a This means that: 2 2 x 2 4 = 2 (2 + 4) = 2 6 = 64 2 1 x 2 4 = 2 (1 + 4) = 2 5 = 32 2 5 x 2 5 = 2 (5 + 5) = 2 10 = 1,024 ZERO POWER Following this logic, this expression must be true: 2 0 x 2 4 = 2 (0 + 4) = 2 4 Therefore: 2 0 x 2 4 = 2 4 can only be true if 2 0 = 1. That looks strange, but it is true. Any number to the zero power is equal to 1. BASE-10 REVISITED Let s return to our base-10 system. Million Hundredthousand Tenthousand Thousand Hundred Ten One 1,000,000 100,000 10,000 1,000 100 10 1 1, 4 6 8, 9 2 5 Another way of saying 1 is 10 0. Another way of saying 10 is 10 1. Another way of saying 100 is 10 2. Do you see the pattern in the columns? 10 6 10 5 10 4 10 3 10 2 10 1 10 0 1,000,000 100,000 10,000 1,000 100 10 1 OTHER BASES If our ancient ancestors had thought to take off their tennis shoes, they might have counted on their fingers and toes, bequeathing Base-20 to us. Indeed, there is no reason why we couldn t have Base-2, Base-8, Base-16, or Base-156, for that matter. You may think that there is something special about Base-10. There isn t. Every single mathematical law or operation works in every other base the only difference is how we represent numbers. Two plus three equals five and 2 + 3 = 5; how you represent the numbers simply doesn t matter. BASE-12 Indeed, humans have not always used Base-10. The earliest numbering system was in Base-12, known as duodecimal or dozenal. We see which we now see in: twelve inches in a foot, twelve months in a year, twelve items in a dozen, twelve signs in the zodiac, twelve hours in a day (and another twelve in a night), circles measured in thirty * twelve degrees, teens begin at thirteen, twelve tones in a chromatic scale, and, twelve pence in a shilling (in merry olde England) Some people argue that for simple, everyday math, Base-12 may be superior to Base-10. For instance, if you have a round number of cookies in Base-10 ten, a hundred, a thousand, or whatever and you want to divide them among three friends, what do you do? Ten is divisible only by five and two. If you have a round number of cookies in Base-12 say, a dozen, one hundred forty-four, or whatever

WAYNE THOMAS SPIES MANAGEMENT INFORMATION SYSTEMS PAGE 95 and you want to divide them, you see that twelve is divisible by 2, 3, 4, and 6. Also while the decimal-centric world thinks that counting to ten on one s fingers is an achievement, note that by using the thumb as a pointer, and counting each finger segment, one can count to twelve easily on each hand. When we count in Base-12, remember that, just as Base- 10 has no symbol for ten, Base-12 has no symbol for twelve. You simply carry the one and add a zero. Note that we will also need a new symbol for ten and eleven: 0 zero 1 one 2 two 3 three 4 four 5 five 6 six 7 seven 8 eight 9 nine X ten (the symbol X, in this context, is pronounced dek ) E eleven (the symbol E is pronounced el ) 10 twelve 11 thirteen 12 fourteen and so on. NUMBER SYSTEMS & COMPUTERS In the computer field, we often encounter four number systems: Base-2, a binary (BIN) system; Base-8, an octal (OCT) system; Base-10, a decimal (DEC) system; and, Base-16, a hexadecimal (HEX) system. BASE-2 Lacking fingers, your computer uses tiny switches to count. A switch must be either on or off; which we represent as 1 or 0. Remember, in Base-10, there is no unique symbol for ten. When you get to ten, you put a 1 in the tens column and a 0 in the ones column. The same idea works in other systems, including Base-2. Just as there is no symbol for ten in Base- 10, there is no unique symbol for two in Base-2. When you get to two, you put a 1 in the twos column and a 0 in the ones column. Counting to ten in Base-2: 1 one 10 two 11 three 100 four 101 five 110 six 111 seven 1000 eight 1001 nine 1010 ten This looks strange the first time you see it, but as you become familiar with manipulating these numerals, it gets easy quickly. The first thing to observe is that, in Base-2, 10 is not the symbol for ten; it s the symbol for two. Obviously, when you go back and forth between number systems, things can get a little hairy if you are unclear which system you are in. To solve this problem, you might mark numerals with subscripts, reflecting their base; for example: 1010 2 = 10 10 Remember how we determined the columns in Base-10: 10 6 10 5 10 4 10 3 10 2 10 1 10 0 1,000,000 100,000 10,000 1,000 100 10 1 It works the same way in Base-2: 2 6 2 5 2 4 2 3 2 2 2 1 2 0 64 32 16 8 4 2 1 "There are only 10 types of people: those who understand binary, and those who don t. CONVERT BINARY TO DECIMAL We can use this to convert any number, in Base-2, into its equivalent in Base-10. For example, let s convert: 11010011 2 to Base-10:

PAGE 96 CHAPTER 15: NUMBER SYSTEMS WAYNE THOMAS SPIES 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 128 64 32 16 8 4 2 1 1 1 0 1 0 0 1 1 x 1 1 x 2 + 2 x 4 + 0 x 8 + 0 x 16 + 16 x 32 + 0 x 64 + 64 x 128 + 128 211 BITS Each 0 or 1 represents the smallest piece of information that a computer can use. This is called a binary digit, or bit. 1 To help understand this, consider a digital watch: What time is this? It is 3:45. Like the switches in a computer, each bar in a digital watch display is the smallest piece of information. Like those switches, bar in a digital watch face can be on or off: Now, what time is this? Time to get a new watch! As you can see, the smallest piece of information on a watch display is meaningless by itself. To display numbers, a digital watch must combine these basic elements into meaningful groups. BYTES Off Similarly, a computer must combine its basic elements bits into meaningful groups. These groups are called bytes. On Just as each number of a digital watch comprises several bars, each of which can be turned on or off to express different values, a byte comprises a set of eight bits, each of which can be turned on or off to create different characters. Each individual character such as A, B, C, 1, 2, or 3 can be expressed by one single byte. The word hello is five bytes long. The phrase : 7 bytes is seven bytes long the space takes up a byte, too. You remember that kilo- is the Greek prefix for 1,000. Thus we say: 1 kilogram = 1,000 grams 1 kilometer = 1,000 meters 1 kilobyte =??? So what is a kilobyte? It s 1,000 bytes, right? Wrong! The problem is fingers or the lack of them. We carbon units have ten fingers. Our idea of a round number is 10 raised to a power: 10 2 (100), 10 3 (1,000), 10 6 (1 million), and so on. A computer has switches instead of fingers. Each switch can be either on or off. As a result, we say that a computer performs its calculations in binary, or base-2. Its idea of a round number is 2 raised to a power: 2 10, 2 20, 2 30, and so on. We call 2 10 bytes a kilobyte, but if we do the math: 2 10 bytes = 1,024 bytes Because that s approximately 1,000, we utilize some semantic rounding and call it a kilobyte, abbreviated KB. Similarly, we refer to a megabyte (MB) as a million bytes, when it is actually 2 20 : 2 20 bytes = 1,048,576 bytes = 1 MB Finally, a gigabyte (GB) is approximately a billion bytes: 2 30 bytes = 1,073,741,824 bytes = 1 GB Thus, we casually refer to a kilobyte as being 1,000 bytes, a megabyte as 1,000 KB, and a gigabyte as 1,000 MB, when, in reality, a kilobyte is 1,024 bytes, a megabyte is 1,024 KB, and a gigabyte is 1,024 MB. The capacity of a computer s memory is measured in megabytes, as is storage capacity. ASCII TEXT You will recall that one byte is composed of eight bits. What is the biggest number that can be expressed with those eight bits?

WAYNE THOMAS SPIES MANAGEMENT INFORMATION SYSTEMS PAGE 97 The largest number that can be represented by eight bits, or one byte, is 11111111, which equals 255. If we assigned a character to each of those numbers, we could represent 255 characters 256, if we include 00000000. 2 That would be more than enough characters to represent each of the letters of the alphabet in upper and lower case, punctuation marks, numbers, and special characters, and still have plenty left over for other things. Someone has done it for us. 3 The American Standard Code for Information Interchange (ASCII, pronounced ASK-ee ) is a standard that assigns the 256 characters of the ASCII character set to the 256 numbers that can be represented by 1 byte. These characters include letters, numbers, punctuation, and control characters (such as line feed, carriage return and tab), but no formatting. Text composed totally of ASCII characters is called, imaginatively, ASCII text, or, sometimes, DOS text, or even plain text. Whatever it s called, it can be read by every computer, regardless of its operating system. The set of ASCII characters appears in Appendix A. ADDING BINARY We add in Base-2 just as we add in Base-10. For example: 0 1 0 0 0 1 1 1 + 0 0 0 0 1 0 1 1? As you would expect: 1 + 1 = 10 1 + 0 = 1 1 + 1 + 1 = 11 Watch as we carry digits to the next column: The solutions are: 1 1 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 1 + 0 0 0 0 1 0 1 0 + 0 0 0 0 0 0 1 1 0 0 0 1 0 1 0 0 0 0 0 0 0 1 1 0 Still, there is an easier way to add a number to itself in Binary. Do you see the pattern here? HEXADECIMAL x x x x x x x + x x x x x x x x x x x x x x 0 In the decimal, or Base-10 system, we count like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Hexadecimal is a Base-16 number system. Just as Base-10 doesn t have a unique character for ten, Base-16 doesn t have a unique character for sixteen but it does have unique characters for ten, eleven, twelve, thirteen, fourteen, and fifteen: 1 2 3 4 5 6 7 8 9 A B C D E F 10 In hexadecimal, B is another way of writing 11 and E is another way of writing 14. CONVERT HEX TO DECIMAL We can use this to convert any number, in Base-16, into its equivalent in Base-10. For example, let s convert: 1 1 1 1 0 1 0 0 0 1 1 1 + 0 0 0 0 1 0 1 1 0 1 0 1 0 0 1 0 Now, what happens when we add a number to itself? Here are two examples: 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 1 + 0 0 0 0 1 0 1 0 + 0 0 0 0 0 0 1 1 to Base-10: 25 16 16 1 16 0 16 1 2 5 x 1 5 x 16 + 32 37

PAGE 98 CHAPTER 15: NUMBER SYSTEMS WAYNE THOMAS SPIES Easy enough. Let s try another; convert: B8 16 to Base-10 (remember: B 16 is eleven, or 11 10 ): 16 1 16 0 16 1 B 8 x 1 8 x 16 + 176 184 NOTES 1 The word bit was coined by Claude Shannon, Bell System Technical Journal, July 1948. 2 Computer scientist Donald E. Knuth awards a hexadecimal dollar to anyone who finds an error in his book. Its value? $2.56. I will leave it to you to figure out why this is so. 3 ASCII was proposed by ANSI in 1963, and adopted in 1968, as a lingua franca for disparate computer systems. It was primarily the product of Bob Bemer, one of the giants of Computer Science.

LAB 5: CALCULATOR Windows comes with a simple calculator that can not only perform arithmetic, it can also help us understand number systems. CALCULATING Calculator can perform all the basic arithmetic operations you would expect. For example, to add three plus two, you would type: 3 + 2 Enter Although the presence of all those highly clickable buttons is tempting, type numbers from the either the Number Pad or Alpha-pad instead of clicking with your mouse. Similarly, type arithmetic operators instead of reaching for that mouse: + addition - * / subtraction multiplication division Pressing Enter is the same as clicking. The scientific view includes all the usual trigonometric, exponential, and logical functions that you would expect to find on a hand-held scientific calculator. CUT & PASTE To copy the results of a calculation to the document on which you are working: Step 1: Perform the calculation in Calculator. Step 2: Press Ctrl C to copy the results to the Clipboard. There is no need to click in the results window or select anything. Step 3: Press Alt Tab to move to the application where you want to place the figures. Step 4: Press Ctrl V to paste it at the cursor. MEMORY In the following image, there is a summary of the Memory function keys, which appear on both the Standard and Scientific calculators: Recall from memory Save to memory KILOBYTE REVISITED On page 106, we learned that a kilobyte is not 1,000 bytes, but that it is 2 10, or 1,024 bytes. We can use Calculator to test our math: Step 1: Open Calculator. Step 2: From the pull-down menu, select View, Scientific view. Step 3: Type: 2 Step 4: Click. Clear memory Subtract from memory Add to memory Step 5: Type: and press Enter. Yes, 2 10 = 1,024. 10 LET S PLAY! How do we express two-hundred in binary? We could count it out, of course, but we can also use Calculator: Step 1: Open Calculator.

PAGE 100 LAB 6: CALCULATOR WAYNE THOMAS SPIES Step 2: From the pull-down menu, select View, Programmer view. 14 Step 3: To convert this decimal to Hexadecimal, click the Hex(adecimal) option. The result is E. Let s try this again. This time, let s convert a number from Base-10 into Base-16: Step 1: Click the Dec(imal) option. Step 2: Type: 37 Step 3: To convert this decimal to Hexadecimal, click the Hex(adecimal) option. The result is 25. Figure 146 Step 3: Note the section along the left that specifies the number system you are in: Hex (= Base 16) Dec (= Base-10) Oct (= Base-8) Bin ( = Base-2) Step 4: Select the Dec (i.e., Base-10) option. Step 5: Type 200. Step 6: Select the Bin (i.e., Base-2) option. Calculator will display 11001000. Now, what would that be in Base-16? Step 7: Select the Hex (i.e., Base-16) option. Calculator will display C8. ANOTHER EXAMPLE Let s test the assertion that: 14 10 = E 16 Step 1: From Calculator s Programmer view, click the Dec(imal) option. Step 2: Type: ADD A NUMBER TO ITSELF REVISITED Back on page 97, we demonstrated how to add a number to itself in Binary. Here is one of the examples: 1 1 0 0 0 0 1 0 1 0 + 0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 Now, let s test this with Calculator: Step 1: With Calculator opened in the Programmer view, click the Bin(ary) option. Step 2: Type: 1010 note that the preceding zeros are assumed. Step 3: Press +. Step 4: Type: Step 5: Press Enter. 1010 The results? 10100, just as we predicted. CONVERT HEX TO DECIMAL We can use this to convert any number, in Base-16, into its equivalent in Base-10. For example, let s convert:

WAYNE THOMAS SPIES MANAGEMENT INFORMATION SYSTEMS PAGE 101 to Base-10: 25 16 The result is 25. Again, we re right. 16 1 16 0 16 1 2 5 x 1 5 x 16 + 32 37 Easy enough. Let s try another; convert: B8 16 to Base-10 (remember: B 16 is eleven, or 11 10 ): 16 1 16 0 16 1 B 8 x 1 8 x 16 + 176 184 ONE LAST EXAMPLE FF is the biggest number we can express with two digits in hexadecimal. What is FF in Hex, when you convert it to Base-10? Step 1: Open Calculator. Step 2: From the pull-down menu, select View, Programmer view. Step 3: Click the Hex option. Step 4: Type: FF Step 5: To convert this decimal to Base10, click the Dec option. The result is 255. That s our last example, but it s one to remember. If anyone ever asks you what your IQ is, say 8C. By their reaction, you may discover theirs. Or not. NOTES CHECK THE RESULTS Again, we can use the Windows Calculator to check our results. First, let s test the assertion that: 14 10 = E 16 To do this: Step 1: With Calculator open in the Programmer view, type: 14 Step 2: To convert this decimal to Hexadecimal, click the Hex(adecimal) option. The result is E. Let s try this again. Earlier, we claimed that: 25 16 = 37 10 Step 1: Click the Dec(imal) option. Step 2: Type: 37 Step 3: To convert this decimal to Hexadecimal, click the Hex(adecimal) option.

PAGE 102 LAB 6: CALCULATOR WAYNE THOMAS SPIES

LAB 6: HTML REVISITED Now that we understand number systems, as well as how to work in them using Windows Calculator, we can return to a problem we had in HTML dealing with color. BACKGROUND COLOR To set the background color of a Web page, use change the property of the <body> tag: <body bgcolor="color "> where color is a so-called named color. For example: <body bgcolor="red"> NAMED COLORS In addition to hexadecimal codes, we can specify sixteen colors by name: black aqua lime silver fuchsia green gray purple olive yellow maroon navy teal red blue white While named colors work in all browsers, other color names might or might not in a given browser. Browser uniformity is essential, so, obviously, straying from these 16 named colors is problematic. COLOR Of course, limiting a Web page to sixteen colors is stifling, given that the human eye can perceive something like 10 million shades of color. Before we solve this problem, it will help to understand some ideas about color. SUBTRACTIVE PRIMARY COLORS In art class, you mixed colored dyes of the subtractive primary colors cyan, magenta, yellow to get black. Subtractive primaries are used with light-reflection, such as ink on paper, or paint on canvas. ADDITIVE PRIMARY COLORS Mix the additive primary colors red, green, blue to get white. The additive primaries are used with light-emitting devices, such as TVs, monitors, tablets, and smart phones. Cathode Ray Tubes (CRTs) in old TVs and monitors fired cathode rays through magnetic fields, which focused them, painting the back of the screen. The back of the screen was coated with phosphor dots that emitted light when the voltage was applied. Light-emitting diode (LED) screens don t use cathode rays, but, instead activate tiny red, green or blue LEDs. Again, more voltage applied to an individual LED means more of that color. Think of each picture element ( pixel ) as a combination of these three primary colors: red, green and blue. By mixing the intensities of these three colors, all colors could be produced. Now, the trick becomes how to tell a pixel how much red, green, or blue to produce. THE RGB METHOD The RGB method specifies intensity of the red, green, and blue cathode ray guns, or of the red, green, and blue LEDs, in six digits: RRGGBB where RR is any two digits representing the intensity of red, GG represents the intensity of green, and BB represents blue. The higher the number, the higher the intensity If are limited to only two digits for each color, the smallest value of any color would be 00, and the highest value would be 99. Each gun or LED, in this digital model, could shoot 100 intensities of light (i.e., 0-99, or 100 possibilities). This means that there are 100 x 100 x 100, or 1,000,000 possible color combinations. Unfortunately, remember that the human eye can see as many as 8 million colors. In the hexadecimal number system, the biggest number we can express in two digits is FF, which you will remember from our last lag, is 255 in Base-10.

PAGE 104 LAB 6: HTML REVISITED WAYNE THOMAS SPIES In the RGB method, each pair of characters represents a color. The first pair represents the red, the second pair represents the green, and the last pair represents the blue component. The bigger the number, the higher the voltage, and the more of that particular color. Using Base-16 thus allows us to render 256 intensities of light (i.e., from 00 to FF) for red, for blue, and for green. That would allow us 256 x 256 x 256) or 16,777,216 color combinations far beyond normal human capabilities in just six digits. HEXADECIMAL COLOR CODES Because the Named Color method is so constraining, HTML also uses the RGB method to specify colors. Each color code begins with an octothorpe ( # ) followed by three pairs of characters. BACKGROUND COLORS Earlier, we set the background color of a Web page by changing the bgcolor property of the <body> tag with a Named Color: <body bgcolor="blue"> Now, let s do this with the RGB method. The general form is: <body bgcolor="#rrggbb"> where #rrggbb is a hexadecimal color code or a color keyword. Therefore, to duplicate: <body bgcolor="blue"> we would use: <body bgcolor="#0000ff"> To get an all-black background, we would usee: <body bgcolor="#000000"> This is identical to: <body bgcolor="black"> BODY TAG & FONTS The bgcolor is a property of the <body> tag. There is only one <body> tag, and it belongs after the </head>. Novices often try to affect the color of individual pieces of text by inserting another <body> tag and altering its text property. Wrong! Do not use more than one <body>, or unpleasant effects may ensue. Instead, use the color property of the <font> tag: <html><head><title>my Page</title></head> <body bgcolor=#ffffff text="#0000ff"> <h1>hello!</h1> <font color="#00ff00">welcome</font> to <font color="#ff0000">colors</font>! </body></html> The results will be similar to Figure 150: Hello! Welcome to colors! Figure 148 NOTES TEXT COLOR To set the text color, use: <body text="#ffffff"> This produces a page with white text. This is identical to: <body text="white"> White text on a white background does not aid reading comprehension.