Converting To And From Hexadecimal Numbers – How To Do It Right

We may have encountered hexadecimal or binary numbers when we tangled without computers or dabbled into programming languages. For most of us, these symbols are no more than streams of information or data from our computers that are too hard to comprehend.

In reality, these codes are important in bridging the information exchange and conversion between human language or text input and machine or computer language, and vice versa. Hexadecimal numbers, or hex, is a base 16 system (uses 16 symbols) that is used as a more friendly and simplified way of representing binary numbers.

Converting to and from hexadecimal numbers can allow us to understand how the computer language works. Here, we’ll discuss how to properly convert to and from hexadecimal numbers while we also try not to get too technical with the discussion.

Converting To From Hexadecimal Header Image

IMAGE: UNSPLASH

Converting Hexadecimal To Binary

First, we’ll examine further how a hexadecimal system works. As previously mentioned, it is a base 16 system that uses 16 symbols, which consist of 10 digits decimal digits (from 0 to 9) and the first six letters of the English alphabet (from A to F). The letters are necessary for the representation of the values 10, 11, 12, 13, 14, and 15 into a single symbol.

When we proceed to convert hexadecimal to binary, we have to remember that each hex symbol or digit is equivalent to a 4-bit binary sequence (for example, the six hex symbol is 0110 in binary and the F hex symbol is 1111 in binary). Applying the given example to the computer’s digital system, which uses a byte (8-bit binary sequence), the combined 6F hexadecimal symbols will convert into 01101111 as 8-bit or byte.

Since a computer’s system processes byte as a basic unit of information, using hexadecimal is a simpler way of representing the binary values, which are the actual language used by computers. Hexadecimal to binary conversion and vice versa is important for programmers because this helps to accurately represent and translate the codes.

The Other Way Around: Binary to Hexadecimal

The more common type of conversion used in programming communities is from binary to hexadecimal. This is understandable since programmers need a simple representation of the long array of binary sequences. By using the hexadecimal number system, the large binary numbers are more conveniently converted into smaller or compact groups. The binary to hexadecimal conversion can be achieved using indirect (decimal or octal conversion) or direct (grouping) methods.

The indirect method uses right-to-left exponential weight assignment method for integers, e.g. 160, 161, 162, 163, and so on, while a left-to-right weight assignment is used for the fractional part, e.g. 16-1, 16-2, 16-3, 16-4, and so on. As an example, the binary sequence 1101010 can be converted first as decimal: (1101010)2 =  1×26+1×25+0x24+1×23+0x22+1×21+0x20 = (106)10 .Then you convert the obtained decimal equivalent to hexadecimal: (106)10 = 6×161+10×160 = (6A)16 , where 6A is the hex conversion.

The direct method does not use weight assignments for the integer and fraction parts of the binary sequence. Instead, it groups the binary input in 4 bits. Long binary sequences are divided into groups of 4 bits, following the right-to-left order for decimals and left-to-right order for fractionals. You can then convert each 4-digit group to a hex digit. For example, converting 1010101101001 using the direct method follows:  (1010101101001)2 = (1 0101 0110 1001)2 = (0001 0101 0110 1001)2 = (1 5 6 9)16 = (1569)16  ,where 1569 is the hex equivalent of the sequence.

Hexadecimal To Text String Conversion

The hex to text string conversion and vice versa are two of the most important conversions in the operation of a computer system. By using the ASCII (American Standard Code for Information Interchange.) code, a standard that assigns numbers ranging from 0 to 127 to represent English characters, like the letters of the alphabet, the digits 0 to 9, and other punctuations and special characters.

For example, the hexadecimal value of 68, which converts as 01101000 in binary, has an equivalent assignment as the lowercase “h” in ASCII. To convert hex to ASCII, you just need a list of ASCII codes and their equivalents and look up the hex code to be converted. This is a convenient list as computer systems only recognize 8-bit binary sequences. A press on any letter on a computer keyboard doesn’t have the same function as pressing a typewriter key where the letter appears on the paper as an impression of the inputted letter.

In computers, the process of displaying letters follows a text string or ASCII to hex, then hex to binary conversion sequence for the input, then the display you see on the screen uses a binary to hex then hex to ASCII sequence. All of these are processed in a tiny fraction of a second, where you can almost instantly see the output after a keypress.

We were able to give an idea of how to convert to and from hexadecimal numbers. Hexadecimal numbers, binary numbers, and ASCII codes are a few of the important data needed for us to interact with our computers. The hex numbers are important for making the interpretation and presentation of computer language more understandable. Although most of us won’t be tackling programming languages or creating computer programs, getting an idea of how the fundamental processes of our computers work can help us appreciate these devices.

If you are interested in even more technology-related articles and information from us here at Bit Rebels, then we have a lot to choose from.

Converting To From Hexadecimal Article Image

IMAGE: UNSPLASH

COMMENTS