Download presentation
Presentation is loading. Please wait.
Published byBlaze Wilcox Modified over 9 years ago
1
How a Computer Processes Information
2
Java – Numbering Systems OBJECTIVE - Introduction to Numbering Systems and their relation to Computer Problems Review of Various Numbering Systems and transitions between systems. How this all relates to Computers and Overflow Errors Practice Applying these concepts to a Numbers Lab Exercise at the end of this discussion.
3
What are the various numbering systems? Decimal Octal Hexadecimal Binary
4
Vocabulary BinaryDecimal HexadecimalOctal Over-Flow ErrorRound-Off Error Under-Flow Error
5
Common Numbering Systems Our every day numbering system is Decimal, or base 10 math. It’s the basis for our currency. Computer Science – uses binary (base 2), octal (base 8, and hexadecimal (base 16) math quite a bit.
6
Review of Decimal System Base 10 math. Used in United States and many other countries. In this system, the right side digit is the ones place, the next left is the tens place, the third on the left if the hundreds place, and then fourth from the right is the thousands place. We only use the numbers zero (0) through nine (9).
7
An example of the number 1,234 would be broken down as follows: 1*1000’s + 2*100’s + 3*10’s + 4*1’s or 1*10 3 + 2*10 2 + 3*10 1 + 4*10 0 Review of Decimal System
8
Decimals (continued) If we move to the right of the decimal place, we start using negative exponents. 10 3 10 2 10 1 10 0 10 -1 10 -2 After understanding how the decimal number system works, it is quite easy to learn other bases, such as base 8 (octal). They all work basically the same way. In base 8, the available digits are 0 through 7, and each number occupies a place value. The place values are: 8 3 8 2 8 1 8 0 8 -1 8 -2
9
Number System Conversions We can designate that a number is in a base other than base 10 (decimal) by using subscripts but if there is no subscript, the number is assumed to be decimal. Let's do some conversions.
10
Octal to Decimal Conversion Let’s use the number 123.6 in base 8 – It is written as 123.6 8. The number 123.68 can be converted to a decimal as: 1*8 2 + 2*8 1 + 3*8 0 + 6*8 -1 1*64 + 2*8 + 3*1 + 6*(1/8) = 83.75
11
Decimal to Octal Conversion Let’s convert the number 567 from the decimal system to the octal system. Start by looking for the largest power of 8 less than 567. This would be 512 or 8 3. So in the 8 3 place value, we put a 1. That leaves us with a remainder of 55. The next place value is 8 2, but 64 is greater than 55 so that place holds a zero. The next place value is 8 1. 55 divided by 8 gives 6 for the 8 1 place value, with a remainder of 7 left over for the next column. The leftover gets placed in the ones column. 8 3 8 2 8 1 8 0 8 -1 8 -2 106700 or 1067 8
12
Hexadecimal Hexadecimal is base 16. Hexadecimal will allow the digits 0 through 15. Using the digits 0 to 9, and then substituting other symbols, the A through F for digits 10 through 15. This base works exactly the same as base 10 and base 8. Let's use the hexadecimal number 34CD and convert it to decimal. This number has the value of: 3*16 3 + 4*16 2 + 12*16 1 + 13*16 0 12288 + 1024 + 192 + 13 13517
13
Hexadecimal So the hexadecimal number 34CD is equivalent to 13517 in base 10 (decimal) and the same process used for octal earlier: 12547 -> 12547/( 16 3 ) -> 3, remainder 259 259/( 16 2 ) -> 1, remainder 3 3/( 16 1 ) -> 0, remainder 3 So 12547 in the decimal number system is equivalent to 3103 16 in the hexadecimal system.
14
Binary Binary works the same way as octal and hexadecimal. Binary is base 2, so the only digits that are used are 0 and 1, and the place values are all powers of 2. A binary digit is called a bit. The place values for binary are shown in the table below. 2 3 2 2 2 1 2 0 2 -1 2 -2 8421½1/4 Let's convert two decimal numbers into the binary system: 13 and 482. The decimal number 13 -> 1101 2 (1*2 3 + 1*2 2 + 0*2 1 +1*2 0 ) The decimal number 482 -> 111100010 2
15
BINARY (Con’t) Calculations for converting 482: Step one – Find the largest power of two that divides into 482. So 2 8, or 256 is the answer. Then subtract 482/256 = 1, to get the leftover, 226. Now see if you can finish this calculation.
16
Now check to see if 2 7, 128 goes into 226. Notice we only have the choice of 1 or 0 so this will be simple to calculate. 226 - 128 -> 98 (another 1) 98-64 -> 34 (another 1) 34-32 ->2 (another 1) can’t subtract 16 (so a 0 goes here) can’t subtract 8 (another 0) can’t subtract 4 (another 0) 2 - 2 -> 0 (another 1) can’t subtract 1 (another 0) Answer: 111100010 2 BINARY (Con’t)
17
Short Cuts Between Binary, Octal, and Hexadecimal Let's convert the binary number 101101011010111 to a hexadecimal number. Binary -> hexadecimal 101101011010111 Starting at the rightmost digit, split the number into groups of 4 - 101 1010 1101 0111
18
Short Cuts Between Binary, Octal, and Hexadecimal Each of these groups has 4 binary digits that can range from 0 -15. This is exactly the value of one hexadecimal digit, so match each group of four bits with one hexadecimal digit. Binary Number GroupsHexadecimal Equivalent 1015 1010A 1101D 01117 So our binary number is equivalent to 5AD7 16. Going from hexadecimal reverses the procedure so each hexadecimal digit expands to 4 bits. The same process occurs between octal and binary using only 3 bits.
19
Let’s Practice - Try the following conversions: 10 110 101 2 -> ___ ____ ____ 8 3F1 16 -> _____ _____ _____ 2 352 8 -> _____ _____ _____ 2 482 ->____________ 2 482 -> ___________ 8 482 -> ________ 16 10001 2 -> _______ 10 5776 8 -> _______ 10 3DB 16 -> _______ 10 110 111 010 2 -> ___ ____ ____ 8 1011 0010 1111 2 -> ___ ____ ____ 16 3FA 16 -> _____ ______ ______ 2 712 8 -> ______ ______ ______ 2
20
Answers to Practice Questions - Answers to Practice Questions: 10 110 101 2 -> 265 8 3F1 16 -> 0011 1111 0001 2 352 8 -> 011 101 010 2 482 -> 0001 1110 0010 2 (Hint: convert to hexadecimal 1st) 482 -> 742 8 482 -> 1E2 16 10001 2 -> 17 10 5776 8 -> 3070 10 3DB 16 -> 987 10 110 111 010 2 -> 672 8 1011 0010 1111 2 -> B2F 16 3FA 16 -> 0011 1111 1010 2 712 8 -> 111 001 010 2
21
How does this all relate to Computers and Overflow Errors? Computers are made up of switches. Each switch is either on or off at any one time. Everything we put into the computer (numbers and letters) must be converted to binary numbers. At some point in time when using a computer, there are not going to be enough bits to accurately represent the decimal numbers in the real world.
22
How does this all relate to Computers and Overflow Errors? Let’s look at a simplified example - hypothesize that we have 8 bits for our numbers and there are no negative numbers. 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 1286432168421 The numbers available to us range from 0000 0000 to 1111 1111 (binary), which is 0 to 255 (decimal). This is not very large for an integer. Attempting to put a larger number into one of our integers would result in an overflow error. Look back at the charts in Lesson A3 for minimum and maximum values for the different types of primitive data types that a computer can use to process information.
23
How does this all relate to Computers and Overflow Errors? The numbers available to us range from 0000 0000 to 1111 1111 (in binary), which is 0 to 255 (in decimals). This is not very large for an integer. Attempting to put a larger number into one of our integers would result in an overflow error. Remember the charts in Lesson A3 for minimum and maximum values for the different types of primitive data types?
24
Primitive Data Types - Values The following table summarizes the bytes allocated and the resulting size. Size Minimum Maximum byte 1 byte -128 127 short 2 bytes -32768 32767 int 4 bytes -2147483648 147483647 long 8 bytes -9223372036854775808 9223372036854775807 Float 4 bytes -3.40282347E+38 3.40282347E+38 double 8 bytes -1.79769313486231570E+308 1.79769313486231570E+308
25
How does this all relate to Computers and Overflow Errors? Other computer problems arise when using numbers that have decimal places. We can still have overflow if we try to put a number that is too large for our storage. There are also round-off errors to deal with. Converting from decimal numbers with fractional parts to a binary representation can cause errors. We are using very simplified versions here, so the errors would usually occur much further out in the decimal places. Most of the time we would not see these errors but as programmers, we need to be aware of them. This is why it is never a good idea to compare two floating numbers using “==”. It is much safer to compare the two and check for a certain level of accuracy. This is also why a programmer should choose the best data type for the job.
26
IN SUMMARY - There are dangers and pitfalls in assuming that a computer will always give you the correct answer. Understanding the inner workings of a computer will help you write better programs. Lastly, hexadecimal numbers are used quite commonly in web design and also in many graphical editing programs.
27
Assignment - Lab A21.1 - Numbers
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.