Hello everybody,
It’s Michael, and today’s lesson will be a little different. There won’t be actual coding involved here, rather, I will discuss a topic which is important in Java-numbering systems.
What’s the point of numbering systems? Think of this way-we communicate with each other with words and numbers, but since computers only understand numbers, numbers are how computers communicate with each other. When we enter data in our programs, that data is converted into electronic pulse, which is then converted into numeric format by ASCII (an acronym for American Standard Code for Information Interchange), which is the system used for encoding characters (whether 0-9, A-Z lowercase or uppercase, or some special characters like the backslash and the semicolon) based off the four main numbering systems (binary, octal, hexadecimal, and decimal). Each character, of which there are 128, has their own unique ASCII value for each of the four numbering systems.
Now, let’s explain each of these four numbering systems:
- Binary is a base-2 number system, as there are only two possible values-0 and 1. 0 represents absence of electronic pulse while 1 represents presence of electronic pulse. A group of four bits, like 1100, is called a nibble while a group of eight bits, like 01010011, is called a byte. The position of each digit in a group of bits represents a certain power of 2.
- To find out the decimal form of 01010011, multiply each 0 and 1 by a power of 2. You can determine which power of two to use based on the position of the 0 or 1 in the group. For instance, the 1 at the end of the group would be multiplied by 2^0, since you would always start with the power of 0. Then work your way left until you reach the last bit in the group (and increase the exponent by 1 each time).
- The number in decimal form is 83, which can be found through this expression (2^0+2^1+2^4+2^6). Granted, you don’t need to worry about the 0 bits, since 0 times anything is 0. And for the 1 bits, you just need to calculate the powers of two and add them together; don’t worry about multiplying 1 to each power since 1 times anything equals itself.
- And remember to ALWAYS start with the power of 0 and work your way left, increasing the exponent by 1 each time.
- Octal is very similar to binary, except it is a base-8 system, so there are 8 possible values-0 to 7 (Java tends to like to start with 0).
- Octal-to-decimal conversions are very much like binary-to-decimal conversions, except you’re dealing with successive powers of 8 as opposed to powers of 2.
- Take the number 145. What would this be in decimal form?
- If you said 101, you’re right. You can find this out using the expression (1*8^2+4*8^1+5*8^0). Remember to multiply each digit by their respective power of 8, then find the sum of all the products.
- And ALWAYS remember to start with the power of 0.
- Decimal is the number system we use every day when talking about numbers; it is a base-10 system, so there are ten possible values (0 to 9). You are probably very familiar with this system, so there’s not much explaining to do here.
- Hexadecimal is an interesting system for a few reasons. First of all, it is a base-16 system, so there are 16 possible values. Secondly, this is the only alphanumeric system of the four I discussed, as this system uses the digits 0-9 and the letters A-F which represent the numbers 10-15.
- Hexadecimal-to-decimal conversions follow the same process as octal-to-decimal and binary-to-decimal conversions, except you’re dealing with successive powers of 16.
- What do you think 45ACB could be in decimal form?
- If you answered 285,387, you’re right. Here’s the expression: (4*16^4+5*16^3+A*16^2+C*16^1+B*16^0). Remember that A is 10, B is 11, C is 12, D is 13, E is 14, and F is 15.
Remember that these four systems aren’t the only possible number systems, as there are other number systems for several different bases. For instance, a base-4 system would use the numbers 0-3 and utilize successive powers of 4 in conversions. Here’s some things to know about other number systems:
- Base-X means that there are X possible values (so base-9 would have 9 possible values)
- The starting point for number systems is always ZERO; the endpoint is X-1 (so 5 would be the endpoint for a base-6 system)
- You would convert base-X numbers to decimal form utilizing successive powers of X (so trying to convert a number in base-5 decimal form would utilize successive powers of 5-5^0, 5^1, and so on), multiplying each digit by the power of X, and finding the sum of all the products.
- When the base is greater than 10, use letters of the alphabet for values above 9. So for base-19, use the letters A-I for the values 10-18.
Now, here are some conversion problems for you. Can you solve them? I will post the answers on the next post:
Binary-to-decimal
- 0110
- 10011
- 1100001
- 1001001
Octal-to-decimal
- 523
- 3455
- 123023
- 2346523
Hexadecimal-to-decimal
- 4BF
- 67AC
- AF12
- 192DCC
Thanks for reading,
Michael
One thought on “Java Lesson 5: Java Numbering Systems”