Computer Science

Hexadecimal Conversion

Hexadecimal conversion is the process of converting numbers from base 10 (decimal) to base 16 (hexadecimal) or vice versa. In computer science, hexadecimal is commonly used to represent binary data in a more human-readable format. Each hexadecimal digit represents four binary digits, making it a convenient way to work with binary data in programming and digital electronics.

Written by Perlego with AI-assistance

8 Key excerpts on "Hexadecimal Conversion"

Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.
  • Introduction to Digital Electronics

    ...Such a base commonly encountered in digital electronics is base-16, which is usually referred to as hexadecimal. The problem of representing numbers greater than 10 is overcome by using the letters A to F to replace the quantities 10 through to 15. Note that hexadecimal numbers are indicated by the use of the subscript H rather than 16. Example 2.3 What is the hexadecimal number AB1C H in base-10? Solution Therefore AB1C H = 43804 10. 2.2.2 Conversion from decimal to base- n Conversion from decimal to base- n is performed by repeated subtraction of the closest approximate number given by a single digit (in base- n) from the remainder of the number to be converted. An example is the best way to illustrate this procedure and so the conversion of 125 10 to base-7 is now given. Firstly, since 125 10 is less than 7 3 = 343 it is the number of 7 2 = 49s that are contained in 125 10 that must first be found. There are 2 since (2×49)=98 (which is less than 125). This leaves 27 10. The 27 10 needs to be made up of 7 1 ’s and 7 0 ’s (i.e. units). Since (3×7)= 21 leaving 6 units, then 125 10 =236 7. Example 2.4 What is 82 10 in base-5? Solution The first three digits in base-5 represent quantities (in base-10) of 1, 5, 25. Since 82-(3×25)=7 and 7-(1×5) = 2, then 82 10 =312 5. Example 2.5 What is 153 10 in binary? Solution Example 2.6 What is 674 10 in hexadecimal? Solution 674 10 = (2×256)+(10×16)+(2×1). Therefore, 674 10 = 2A2 H. 2.2.3 Binary and hexadecimal The bases of most importance in digital electronics are binary and hexadecimal (base-2 and base-16). So, it is worth looking at conversion between these as a special case. 4 The reason hexadecimal is commonplace is because the wires in digitial circuits are often grouped into buses of 16 for addressing solid state memory and other devices. The first four least significant digits of a binary number encode the numbers, in base-10, from 0 to 15. This is the range covered by the least significant digit in hexadecimal...

  • Programmable Controllers for Factory Automation
    • David Johnson(Author)
    • 2020(Publication Date)
    • CRC Press
      (Publisher)

    ...As the name suggests, this system has as its base the number 8. The octal system is occasionally used as the I/O addressing convention in some programmable controllers, and as the data referencing convention in a few, especially those with eight-bit word system architectures. The octal system uses the numbers 0 through 7 as its operating range. There are no 8 or 9, and the progression in counting follows a “six, seven, ten, eleven…’’sequence. This is shown in Table 3.2. The process of converting the base eight numbers to decimal or base ten numbers, is similar to that shown for binary numbers and an example is shown in Figure 3.3. Table 3.2 Decimal and Octal Equivalents Decimal Octal 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 10 9 11 10 12 11 13 12 14 13 15 14 16 15 17 Figure 3.3 Diagram of octal to decimal conversions. The last system we shall consider for now, is the hexadecimal. This numbering system is based on the number 16. The name comes from hex for six and deci for ten; or six plus ten. Hexadecimal numbers are used a great deal in many programmable controller systems. They are especially useful as references on the programming device, as a great amount of binary information can be encoded in a condensed hexadecimal format. This is illustrated in Table 3.3, contrasting hexadecimal with both decimal and binary. You will note that only one character of information in the hexadecimal format is required to encode four characters of binary information. Figure 3.4 shows a conversion example of hexadecimal to decimal and hexadecimal to binary. Table 3.3 Hexadecimal Equivalents in Binary and Decimal Binary Decimal Hexadecimal 0000 0 0 0001 1 1 0010 2 2 0011 3 3 0100 4 4 0101 5 5 0110 6 6 0111 7 7 1000 8 8 1001 9 9 1010 1 0 A 1011 11 B 1100 12 C 1101 13 D 1110 14 E 1111 15 F Figure 3.4 Diagram of hexadecimal to decimal and binary conversions. 3.2 CODING TECHNIQUES AND CONVENTIONS In many applications involving programmable controllers, it is...

  • Microprocessor Technology
    • J S Anderson(Author)
    • 2012(Publication Date)
    • Routledge
      (Publisher)

    ...Furthermore, we have also learned that this is the only language the microprocessor understands and we're stuck with it. Imagine having to program a computer using only binary codes. In fact, this is how it used to be done and apart from the disadvantages just mentioned, the problem of avoiding errors was enormous. Clearly a better system of representing binary numbers is required. Such a system exists in the hexadecimal code. Hexadecimal numbers We have seen that it is usual to put binary numbers together in groups of four, so it would be useful to be able to represent each group of four with a single digit. However, the maximum number which can be represented by four binary digits is 15, i.e. HUB = 15D, and 15 does, of course, contain two digits. For this reason, the hexadecimal code has been invented. The numbers 0 to 9 are used as in the decimal system and the remaining six numbers (10 to 15) are represented by the first six letters of the alphabet. These hexadecimal numbers are shown in Table 2.2. We have seen that decimal 64,424 is equivalent to 1111 1011 1010 1000 in binary. In order to represent this number in hexadecimal we could simply make use of Table 2.2 as shown below: 1111 1011 1010 1000 F B A 8 hence: 1111 1011 1010 1000B becomes FBA8H which is a lot neater and can be input directly into most microelectronic systems. Generally, where this is possible, the computer will require you to include a leading zero whenever the hexadecimal number begins with a letter (to distinguish the number from a label) and to follow the number with the letter ‘H’ (to distinguish it from a decimal number). Hence, the correct format is 0FBA8H. Some systems allow hexadecimal numbers to be input from a numeric keypad (for example, systems like the ‘EMMA’ which do not support a VDU). 6502 systems often represent a hexadecimal number by using the ‘&’ prefix (though sometimes a ‘$’ is used), hence 0FBA8H would be represented as #&FBA8 (or $FBA8)...

  • Basic Electricity and Electronics for Control: Fundamentals and Applications, Third Edition

    ...You are familiar with the decimal system. Decimal means that the number system is based on ten digits. Its base is ten. The only numbers allowed in the decimal system are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. All the numbers that we can use to describe numerical quantities in decimal are made up of those ten numbers and no others. Figure 18–1 illustrates the powers of ten. Notice that a number, such as 4,302.63, is really 4000 + 300 + 2 +.6 +.03, or more correctly, 4 × 1000 (10 to the third power) + 3 × 100 (10 to the second power) + 0 × 10 (10 to the first power) + 2 × 1 (10 to the 0 power or 1) + 6 × 1 × 1/10 (10 to the –1 power) + 3 × 1 × 1/100 (10 to the –2 power). The number represented in Figure 18–1 is 4302.63 Figure 18–1 Example of Powers of 10. All other number systems will be constructed in the same way, except that rather than ten as the base, they are based on a different number, for example, two if binary or sixteen if hexadecimal. For this chapter’s review of number systems, the emphasis will be on using the number system as a form of pattern recognition. The number systems chosen here are the ones currently used in data communications. Binary is the number system used by computers, decimal is used to represent binary values so they make sense to humans, and hexadecimal is used to reduce binary streams to recognizable patterns. Computers presently only work with binary patterns, and humans only really understand decimal. THE BINARY SYSTEM Figure 18–2 illustrates the binary values for 0 through 15 in decimal form. The binary patterns for the decimal values 0 through 9 are called binary coded decimal (BCD). This means that the decimal numbers (0 through 9) are each represented by four binary digits: 1   3   0   2                     Decimal 0001 0011 0000 0010   BCD This coding (BCD) was done so humans could see familiar-looking numbers rather than strings of ones and zeros...

  • Programmable Logic Controllers
    • William Bolton(Author)
    • 2015(Publication Date)
    • Newnes
      (Publisher)

    ...To convert from denary numbers into hex we successively divide by 16 and note the remainders. Thus the denary number 156, when divided by 16, gives 9 with remainder 12, and so in hex is 9C. To convert from hex to denary, we multiply the digits by the power of 16 appropriate to its position in the number. Thus hex 12 is 1 × 16 1 + 2 × 16 0 = 18. To convert binary numbers into hexadecimal numbers, we group the binary numbers into fours starting from the least significant number. Thus, for the binary number 1110100110 we have: 11 1010 0110 Binary number 3 A 6 Hex number For conversion from hex to binary, each hex number is converted to its 4-bit equivalent. Thus, for the hex number 1D we have 0001 for the 1 and 1101 for the D: 1 D Hex number 0001 1101 Binary number Thus the binary number is 0001 1101. 3.3 Binary Coded Decimals Because the external world tends to deal mainly with numbers in the denary system and computers with numbers in the binary system, there is always the problem of conversion. There is, however, no simple link between the position of digits in a denary number and the position of digits in a binary number. An alternative method that is often used is the binary coded decimal system (BCD). With this system, each denary digit is coded separately in binary. For example, the denary number 15 has the 5 converted into the binary number 0101 and the 1 into 0001: 1 5 Denary number 0001 0101 Binary number to give the number 0001 0101 in BCD. With the BCD system, the largest decimal number that can be displayed is a 9, and so the four binary digits are 1001. To convert a BCD number to a denary number, each group of four binary numbers is separately converted to a denary number. For example, the BCD number 0011 1001 has a denary number of 3 for 0011 and 9 for 1001, and so the denary number is 39. 0011 1001 BCD number 3 9 Denary number Numeric data is often entered into PLCs by rotary or thumb-wheel switches with a 0 to 9 range...

  • Programmable Logic Controllers
    • William Bolton(Author)
    • 2011(Publication Date)
    • Newnes
      (Publisher)

    ...The conversion of a binary number to a denary number thus involves the addition of the powers of 2 indicated by the number. The conversion of a denary number to a binary number involves looking for the appropriate powers of 2. We can do this by successive divisions by 2, noting the remainders at each division. Thus with the denary number 31: The binary number is 11111. The first division gives the least significant bit because we have just divided the 31 by 2, i.e. 2 1 and found 1 left over for the 2° digit. The last division gives the most significant bit because the 31 has then been divided by 2 four times, i.e. 2 4 and the remainder is 1. 3.2 Octal and hexadecimal Binary numbers are used in computers because the two states represented by 0 and 1 are easy to deal with switching circuits where they can represent off and on. A problem with binary numbers is that a comparatively small number requires a large number of digits. For example, the denary number 9 which involves just a single digit requires four when written as the binary number 1001. The denary number 181, involving three digits, in binary form is 10110101 and requires eight digits. Because of this, octal or hexadecimal numbers are sometimes used to make numbers easier to handle and act as a ‘half-way house’ between denary numbers and the binary numbers which computers work with. 3.2.1 Octal system The octal system is based on eight digits: 0, 1, 2, 3, 4, 5, 6, 7. When a number is represented by this system, the digit position in the number indicates the weight attached to each digit, the weighting increasing by a factor of 8 as we proceed from right to left. Thus we have: To convert denary numbers to octal we successively divide by 8 and note the remainders. Thus the denary number 15 divided by 8 gives 1 with remainder 7 and thus the denary number 15 is 17 in the octal system. To convert from octal to denary we multiply the digits by the power of 8 appropriate to its position in the number...

  • Programmable Logic Controllers
    • William Bolton(Author)
    • 2009(Publication Date)
    • Newnes
      (Publisher)

    ...To convert from denary numbers into hex we successively divide by 16 and note the remainders. Thus the denary number 156, when divided by 16, gives 9 with remainder 12, and so in hex is 9C. To convert from hex to denary, we multiply the digits by the power of 16 appropriate to its position in the number. Thus hex 12 is 1 × 16 1 + 2 × 16 0 = 18. To convert binary numbers into hexadecimal numbers, we group the binary numbers into fours starting from the least significant number. Thus, for the binary number 1110100110 we have: 11 1010 0110 Binary number 3 A 6 Hex number For conversion from hex to binary, each hex number is converted to its 4-bit equivalent. Thus, for the hex number 1D we have 0001 for the 1 and 1101 for the D: 1 D Hex number 0001 1101 Binary number Thus the binary number is 0001 1101. 3.3. Binary Coded Decimals Because the external world tends to deal mainly with numbers in the denary system and computers with numbers in the binary system, there is always the problem of conversion. There is, however, no simple link between the position of digits in a denary number and the position of digits in a binary number. An alternative method that is often used is the binary coded decimal system (BCD). With this system, each denary digit is coded separately in binary. For example, the denary number 15 has the 5 converted into the binary number 0101 and the 1 into 0001: 1 5 Denary number 0001 0101 Binary number to give the number 0001 0101 in BCD. With the BCD system, the largest decimal number that can be displayed is a 9, and so the four binary digits are 1001. To convert a BCD number to a denary number, each group of four binary numbers is separately converted to a denary number. For example, the BCD number 0011 1001 has a denary number of 3 for 0011 and 9 for 1001, and so the denary number is 39. 0011 1001 BCD number 3 9 Denary number Numeric data is often entered into PLCs by rotary or thumb-wheel switches with a 0 to 9 range...

  • Electronic Logic Circuits
    • J. Gibson(Author)
    • 2013(Publication Date)
    • Routledge
      (Publisher)

    ...Appendix A Number Systems and Base Conversions Number systems and number representation using a fixed base were described in Chapter 1. The use of a base of ten gives the familiar decimal number system which requires only ten different symbols to represent all possible numbers. Usually the symbols chosen are the printed ones 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9; it is assumed that readers are familiar with decimal numbers and are able to manipulate them as required to perform calculations. When the signals in logic networks are used to represent numeric values the numbers are usually in binary form, that is, the value of the base is two. Binary numbers require only two digit symbols to represent a single unit (one) and nothing (zero, or null). Generally the symbols 1 and 0 are chosen for the digits of printed binary numbers as they are already familiar from their use in the decimal (denary) system. An example of a binary number is 10111011·11001 2 where the subscript 2 is used to indicate that this is a binary number; without the subscript the number could be one with any base. Using decimal notation and values for the powers of two this number is equivalent to which is more conveniently written as giving 187.78125 10 as the total. Here the subscript 10 indicates that the printed number is a decimal number (base ten). A.1 Conversions between the binary and decimal systems Provided that numbers to be converted do not have either a very large or a very small magnitude then a simple method of converting a binary number into its decimal equivalent is the technique already illustrated in which each digit is multiplied by the weight, 2 n, expressed as a decimal number. The value of the weight is set by the digit position relative to that of the point...