How to Convert Hex to Binary and Binary to Hexadecimal

Updated on September 9, 2019
eugbug profile image

Eugene is a qualified control/instrumentation engineer Bsc (Eng) and has worked as a developer of electronics & software for SCADA systems.

The Hexadecimal Numbering System

The base 16, also known as hexadecimal (abbreviated to hex) numbering system is regularly used in computer coding for conveniently representing a byte or word of data. This guide shows you how to convert from hex to binary and binary to hexadecimal.

If you consider this information useful, please show your appreciation by sharing on Facebook, Pinterest etc.
Thanks!

hex and binary representations of a number
hex and binary representations of a number | Source

Decimal, the Base 10 Numbering System

Before we learn how to convert hex to binary, let's try and understand how the base 10 system works.

The decimal, also known as the denary or base 10 numbering system that we use in everyday life makes use of ten symbols or numerals: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.

So to count you start with 0, then continue 1...2...3...4...5...6...7...8...9

What happens when you get to ten? There's no numeral for ten, so it's represented as

10

Which means 1 ten and no units

Similarly when you get to 99, there's no numeral for one hundred, so you write one hundred as 100.

So writing a number in the base 10 system involves using numerals in a "units", "tens", "hundreds", "thousands" place and so on

So 145 really means "one hundred, 4 tens and 5 units" although we just think of it as one hundred and forty five.

Hexadecimal, the Base 16 Numbering System

Hexadecimal or "hex" is a numbering system which uses 16 different numerals. We saw that decimal used ten numerals from 0 to 9. Hex expands on this by adding six more, the capital letters A, B, C, D, E and F.

So to count from 0 to 15 you go 0...1...2...3...4...5...6...7...8...9

But what happens next?

Simply continue with A...B...C...D...E...F which represents 10, 11, 12, 13, 14 and 15 decimal.

In the decimal system, we saw that when we got to nine, there was no numeral for ten so it was represented as 10 or "one ten and no units".

In the hex system when we get to F which is 15 decimal, we have to represent the next number sixteen as 10 or "one 16 and no units".

Binary, the Base 2 Numbering System

The binary system used by computers is based on 2 numerals; 0 and 1. So you count 0, 1, there is no numeral for 2, so 2 is represented by 10 or "one 2 and no units". In the same way that there is a units, tens, hundreds, thousands place in the decimal system, in the binary system there is a units, twos, fours, eights, sixteens place etc. in the binary system.

Decimal to Hex and Binary Table

Decimal
Hex
Binary
0
0
0
1
1
1
2
2
10
3
3
11
4
4
100
5
5
101
6
6
110
7
7
111
8
8
1000
9
9
1001
10
A
1010
11
B
1011
12
C
1100
13
D
1101
14
E
1110
15
F
1111
16
10
10000
17
11
10001
18
12
10010
19
13
10011
20
14
10100
...
...
...
25
19
11001
26
1A
11010
27
1B
11011
28
1C
11100
29
1D
11101
30
1E
11110
31
1F
11111
32
20
100000
33
21
100001
34
22
100010
Binary, decimal and hex equivalents.

Indicating the Base of a Number

If a number isn't decimal (base 10), the base can be explicitly indicated by a subscript to avoid confusion. Sometimes the subscript is omitted to avoid excessive detail if the base has been specified earlier in a discussion or if numbers are listed in a table (e.g. numbers may be indicated as hex in the title of the table).

So for instance 1F hex (31 decimal) can be written 1F16

Steps to Convert Hex to Binary

Hex is very easy to convert to binary.

  1. Write down the hex number and represent each hex digit by its binary equivalent number from the table above.
  2. Use 4 digits and add insignificant leading zeros if the binary number has less than 4 digits. E.g. Write 102 (2 decimal) as 00102.
  3. Then concatenate or string all the digits together.
  4. Discard any leading zeros at the left of the binary number.

Converting hex to binary
Converting hex to binary | Source

Most Significant Bit (MSB) and Least Significant Bit (LSB)

For a binary number, the most significant bit (MSB) is the digit furthermost to the left of the number and the least significant bit (LSB) is the rightmost digit.

Most significant bit (MSB) and least significant bit (LSB).
Most significant bit (MSB) and least significant bit (LSB). | Source

Steps to Convert Binary to Hex

Binary is also easy to convert to hex.

  1. Start from the least significant bit (LSB) at the right of the binary number and divide it up into groups of 4 digits. (4 digital bits is called a "nibble").
  2. Convert each group of 4 binary digits to its equivalent hex value (see table above).
  3. Concatenate the results together, giving the total hex number.

Converting binary to hex
Converting binary to hex | Source

What is Hex Used For?

Because of the ease of converting from hex to binary and vice versa, it's a convenient shorthand for representing byte values i.e. numbers from 0 to 255. Also it's compact requiring only 2 digits for a byte and 4 digits for a word.

  • Hex dumps are used to display the values of bytes in files. Each byte value is displayed as hex
  • Assembly language is written as a series of mnemonic (short, easy to remember word) instructions for a microprocessor. The operand (the data operated on by an opcode) is commonly specified as a hex value. It's also used to indicate the storage location of data

Example of assembly language instruction

In the short code segment below, MOV is the opcode (instruction) and 61 hex is the operand that the opcode acts on. AL is a register that stores a value temporarily so that arithmetic can be done on it before it's moved to memory. A program called an assembler converts the human understandable assembly language to machine code.

MOV AL, 61H ; Load AL register with 61 hex (97 decimal )

Assembly Language Program for an 8 Bit Microprocessor

An assembly language listing for a Motorola 6800 8-bit microprocessor
An assembly language listing for a Motorola 6800 8-bit microprocessor | Source

Hex Dump of a File

A hex dump of a JPG file as viewed in a file editor. On the left, each byte is displayed as hex. On the right, alphanumeric characters corresponding to ASCII values are displayed.
A hex dump of a JPG file as viewed in a file editor. On the left, each byte is displayed as hex. On the right, alphanumeric characters corresponding to ASCII values are displayed. | Source

How to Convert Decimal to Binary

To convert decimal to binary and binary to decimal, see my other guide:

How to Convert Decimal to Binary and Binary to Decimal

What is Binary Used For?

For more details on how binary is used in computer systems and digital electronics, see my other article:

Why is Binary Used In Computers and Electronics?

How to Convert Hex to Decimal

You can convert hex to decimal by simply multiplying each hex numeral by the placeholder's value as a power of 16 and adding the result. (F16 = 15 decimal and A16 = 10 decimal)

Example: What is the decimal equivalent of 52FA16 ?

52FA16 = 5 x 163 + 2 x 162 + 15 x 161 + 10 x 160

= 5 x 4096 + 2 x 256 + 5 x 16 + 10 x 1

= 21,242

Questions & Answers

  • What is the hexadecimal value of 10110?

    It's 16.

  • What is an octal number?

    Octal numbers use 8 symbols rather than 10 as in the base 10 or denary system we use for normal counting.

    So in octal, we count 0, 1, 2, 3, 4, 5, 6, 7

    Eight is represented as 10 because we don't use the symbols 8 and 9

    This is like the way ten is represented in the base 10 system by the symbols 1 and 0, i.e. we write ten as 10 because there's no symbol for ten.

    Everytime an octal number reaches a power of 8, we add a new place digit.

    So 64 is 100 in octal just like one hundred is 100 in the base 10 numbering system

  • What is a use of octal?

    It can be used as a shorter representation of binary (just like hex).

    For instance, the number 01011101 can be grouped into groups of three digits (in this case add a lead "0"), The number then becomes 135 octal.

© 2018 Eugene Brennan

Comments

    0 of 8192 characters used
    Post Comment
    • profile image

      onesmus 

      7 weeks ago

      thank you

    • profile image

      captain marvel 

      2 months ago

      thank you for the information.....

    • profile image

      Athena Crane 

      2 months ago

      nice ive learned

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, owlcation.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://owlcation.com/privacy-policy#gdpr

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
    ClickscoThis is a data management platform studying reader behavior (Privacy Policy)