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
    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 AB1CH in base-10?
    Solution
    Therefore AB1CH = 4380410 .

    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 12510 to base-7 is now given.
    Firstly, since 12510 is less than 73 = 343 it is the number of 72 = 49s that are contained in 12510 that must first be found. There are 2 since (2×49)=98 (which is less than 125). This leaves 2710 .
    The 2710 needs to be made up of 71 ’s and 70 ’s (i.e. units). Since (3×7)= 21 leaving 6 units, then 12510 =2367 .
    Example 2.4
    What is 8210 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 8210 =3125 .
    Example 2.5
    What is 15310 in binary?
    Solution
    Example 2.6
    What is 67410 in hexadecimal?
    Solution
    67410 = (2×256)+(10×16)+(2×1). Therefore, 67410 = 2A2H .

    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. The next four binary digits allow this range to be extended to cover up to 25510 (by using the numbers 1610 , 3210 , 6410 and 12810 , i.e. the numbers represented by these binary digits, as appropriate). Correspondingly, the second hexadecimal digit enables numbers requiring up to FH = 1510 multiples of 1610 to be encoded. Hence, conversion from base-2 to hexadecimal can be performed by operating on blocks of four binary digits to produce the equivalent single hexadecimal digit.5
  • Programmable Controllers for Factory Automation
    • David Johnson(Author)
    • 2020(Publication Date)
    • CRC Press
      (Publisher)
    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 necessary to encode and decode information. This normally involves interaction with external devices like CRT terminals or thumbwheel switch interfaces. These external devices communicate to the programmable controller primarily in one of two ways. One is to use regular input/output lines of a certain voltage, usually 24 volts DC. This is most commonly used with devices like thumbwheel switch interfaces and digital LED display devices. The second is to use digitally encoded information sent and received through one of the programmable controller’s data communication interfaces. We will examine some of the more common techniques of coding below along with some system examples.
  • Microprocessor Technology
    • J S Anderson(Author)
    • 2012(Publication Date)
    • Routledge
      (Publisher)
    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). The ‘#’ (hash) symbol indicates that the value is a number rather than a memory address. Obviously, the reader will need to become familiar with the conventions associated with the hardware being used; Z80 systems receive the most attention in this book, but substantial information is also presented for 6502 users.
  • Basic Electricity and Electronics for Control: Fundamentals and Applications, Third Edition
    All number systems follow the same rules. 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. BCD coding is used to represent decimal values in a binary format.
  • Programmable Logic Controllers
    • William Bolton(Author)
    • 2015(Publication Date)
    • Newnes
      (Publisher)
    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. Thus there may be a bank of such switches, one giving, say, the hundreds, one the tens, and one the ones. The output from each switch is then converted, independently, into binary to give the overall result of a binary coded decimal number. Some PLCs have a function that can be called up to convert such BCD numbers to binary numbers; in other PLCs it has to be done by programming.
  • Programmable Logic Controllers
    • William Bolton(Author)
    • 2011(Publication Date)
    • Newnes
      (Publisher)
    Thus the denary equivalent is 10. 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. 21 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. 24 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. For example, the octal number 365 is 3 × 82 + 6 × 81
  • Programmable Logic Controllers
    • William Bolton(Author)
    • 2009(Publication Date)
    • Newnes
      (Publisher)
    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. Thus there may be a bank of such switches, one giving, say, the hundreds, one the tens, and one the ones. The output from each switch is then converted, independently, into binary to give the overall result of a binary coded decimal number. Some PLCs have a function that can be called up to convert such BCD numbers to binary numbers; in other PLCs it has to be done by programming.
  • 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·110012 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.7812510 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