When you learned Java, you must have read about various numbering systems supported by JDK.For example when we append a single 0 before an int, it becomes octal and if 0x is appended then it becomes hexadecimal. Recently while programming, I have been thinking about real world scenario where we can use various numbering systems like octal, binary and hexadecimal apart from decimal. I came up with the following list and wanted to share:

Binary: The original number system for computers

  • Binary numbers are everywhere used and this system is inherent to computers. There are dedicated data types for binary number system like BitSet, Byte arrays etc.
  • Networking based routing programs use binary system for IP address calculations like finding the sub-net of a host, assigning gateway, routing a packet etc.
  • From java 7 onwards, binary literals can be directly assigned to int variables by using something like 0b101010101.

HexaDecimal : The one that has replaces binary values almost everywhere

  • 64-based encoding systems like Base64 which encode the binary data in hexadecimal are very good example where hexadecimal number system is used. Base64 is used
  • Printer, Bar coders and other hardware interaction commands are usually hexadecimal codes. So programs having hardware interaction have to use this number system.
  • For graphics based systems, the color codes are represented as hexadecimal values and hence again this number system can’t be avoided where colors are involved.
  • Any java de-compiler will definitely need to handle hexadecimal values for conversion of byte code to source code.

Octal : The one loved by Unix

  • Unix File permissions. Many java programs interact with Unix based systems where they need to send UNIX commands and have them executed by the operating system. The file permissions in Unix are usually three bits viz. Read, Write and Execute. Octal number system suits this requirement as octal also has three number positions.
  • Some digital displays especially seven segment displays use the octal number system for creating mapping between which portion of display will be lit.
  • Some ancient systems around year 1700 used 18bit word sizes which can nicely be represented using octal number system.
Use Case for Binary, Octal and HexaDecimal in Java admin Core Java
When you learned Java, you must have read about various numbering systems supported by JDK.For example when we append a single 0 before an int, it becomes octal and if 0x is appended then it becomes hexadecimal. Recently while programming, I have been thinking about real world scenario where...
When you learned Java, you must have read about various numbering systems supported by JDK.For example when we append a single 0 before an int, it becomes octal and if 0x is appended then it becomes hexadecimal. Recently while programming, I have been thinking about real world scenario where we can use various numbering systems like octal, binary and hexadecimal apart from decimal. I came up with the following list and wanted to share: <h3>Binary: The original number system for computers</h3> <ul> <li>Binary numbers are everywhere used and this system is inherent to computers. There are dedicated data types for binary number system like BitSet, Byte arrays etc.</li> <li>Networking based routing programs use binary system for IP address calculations like finding the sub-net of a host, assigning gateway, routing a packet etc.</li> <li>From java 7 onwards, binary literals can be directly assigned to int variables by using something like 0b101010101.</li> </ul> <h3>HexaDecimal : The one that has replaces binary values almost everywhere</h3> <ul> <li>64-based encoding systems like Base64 which encode the binary data in hexadecimal are very good example where hexadecimal number system is used. Base64 is used </li> <li>Printer, Bar coders and other hardware interaction commands are usually hexadecimal codes. So programs having hardware interaction have to use this number system.</li> <li>For graphics based systems, the color codes are represented as hexadecimal values and hence again this number system can't be avoided where colors are involved.</li> <li>Any java de-compiler will definitely need to handle hexadecimal values for conversion of byte code to source code.</li> </ul> <h3>Octal : The one loved by Unix</h3> <ul> <li>Unix File permissions. Many java programs interact with Unix based systems where they need to send UNIX commands and have them executed by the operating system. The file permissions in Unix are usually three bits viz. Read, Write and Execute. Octal number system suits this requirement as octal also has three number positions.</li> <li>Some digital displays especially seven segment displays use the octal number system for creating mapping between which portion of display will be lit. </li> <li>Some ancient systems around year 1700 used 18bit word sizes which can nicely be represented using octal number system.</li> </ul>
The following two tabs change content below.
I run this blog with lots of passion. In this website, you will find tutorials on Core Java, Spring, Struts, Web Applications, Portals and Database. Please support me and the website by sharing the posts on your facebook / twitter. You can tap the share button at the top of each post. Thanks for the support.