How to use the BIN2HEX function
What is the BIN2HEX function?
The BIN2HEX function converts a binary number to a hexadecimal number.
Table of Contents
1. Introduction
What is the binary system?
The binary system is a positional numeral system that uses only two digits: 0 and 1. The binary system is important in our society, many devices like computers, digital cameras, mobile phones and modern cars use binary code to store, process and communicate data. The binary numeral system makes it easy to store and transmit data using binary digits or bits.
What is a bit?
A bit is a binary digit. It is the most basic unit of information in binary communication and computing. The bit can either be the value 0 (zero) or 1, a bit can also be part of a larger sequence of bits that can represent numbers, characters, and other types of data.
The following table shows the binary, decimal and hexadecimal values from 0 (zero) to 17.
Binary | Decimal | Hexadecimal |
00000000 | 0 | 0 |
00000001 | 1 | 1 |
00000010 | 2 | 2 |
00000011 | 3 | 3 |
00000100 | 4 | 4 |
00000101 | 5 | 5 |
00000110 | 6 | 6 |
00000111 | 7 | 7 |
00001000 | 8 | 8 |
00001001 | 9 | 9 |
00001010 | 10 | A |
00001011 | 11 | B |
00001100 | 12 | C |
00001101 | 13 | D |
00001110 | 14 | E |
00001111 | 15 | F |
00010000 | 16 | 10 |
00010001 | 17 | 11 |
What is a hexadecimal number?
A hexadecimal number is a number with a base of 16, for example, the decimal system uses a base of 10. This means that each digit in a hexadecimal number can have 16 possible values, from 0 to 15, however, the letters A to F are used from 10 to 15. See the hexadecimal column in the table above.
Hexadecimal numbers are often used in computers, the reason is they represent four binary digits (bits) with one hexadecimal digit. For example, the binary number 1010 is equivalent to the hexadecimal number A.
Hexadecimals make it easier to write big numbers with less digits, in other words, hexadecimals shorten binary digits considerably. For example, we can use hexadecimal to show the values of colors and MAC addresses in computers.
What are the different conversion functions related to BIN2HEX in Excel?
Excel Function | Description |
---|---|
BIN2DEC | Converts a binary number (base-2) to decimal (base-10) |
BIN2OCT | Converts a binary number to octal (base-8) |
BIN2HEX | Converts a binary number to hexadecimal (base-16) |
OCT2DEC | Converts an octal number to decimal |
OCT2HEX | Converts an octal number to hexadecimal |
OCT2BIN | Converts an octal number to binary |
DEC2BIN | Converts a decimal number to binary |
DEC2OCT | Converts a decimal number to octal |
DEC2HEX | Converts a decimal number to hexadecimal |
HEX2DEC | Converts a hexadecimal number to decimal |
HEX2OCT | Converts a hexadecimal number to octal |
HEX2BIN | Converts a hexadecimal number to binary |
1. Syntax
BIN2HEX(number,[places])
2. Arguments
number | Required. The binary number you want to convert to hexadecimal. The sign bit is the most significant bit of number, the following 9 bits are magnitude bits. Negative numbers are represented using two's-complement notation. |
[places] | Optional. The number of characters to use. If not entered the minimum number of characters is used. Use this argument to add leading 0 (zeros). |
What is a sign bit?
The sign bit indicates whether a binary number is positive or negative, if the bit is 0 the number is positive, if the bit is 1, the number is negative.
What is a magnitude bit?
The remaining 9 bits are magnitude bits which represents the absolute value of the number. An absolute number is a number without the sign.
What is two's-complement notation?
Two’s-complement notation is used to represent negative numbers, the magnitude bits are changed from 0 to 1 and 1 to 0 and adding 1 to the result. For example:
Decimal number +9 using 10 bits is 0000001001.
Decimal number -9 using 10 bits is 1111110110 + 1 = 1111110111
3. Example
The image above demonstrates the BIN2HEX function in cells C3, C4, C5, and C6. It calculates the hexadecimal values based on the corresponding cells which contain different binary numbers.
Formula in cell B3:
The first cell B3 contains 0000011001 and the BIN2HEX function returns 19 in cell C3, the second cell B4 contains 0000000011 and the BIN2HEX function returns 3.
The third cell B5 contains 0000000100 and the BIN2HEX function returns 4 in cell C3, the fifth cell B6 contains 0011111111 and the BIN2HEX function returns FF.
The next section describes how these values are calculated in detail.
4. How is the BIN2HEX function calculated in detail?
Binary | Hexadecimal |
0000 | 0 |
0001 | 1 |
0010 | 2 |
0011 | 3 |
0100 | 4 |
0101 | 5 |
0110 | 6 |
0111 | 7 |
1000 | 8 |
1001 | 9 |
1010 | A |
1011 | B |
1100 | C |
1101 | D |
1110 | E |
1111 | F |
- Split the binary number into groups of four digits starting from the right.
- If the last group has less than four digits, add zeros to the left to make it four digits.
- Use the table above to find the corresponding hexadecimal digit for each group of four digits.
5. BIN2HEX function not working
BIN2HEX returns the #NUM! error value if
- more than 10 binary digits are used. See cells B3 and C3 in the image above.
- the number is not a valid binary number. See cells B4 and C4 in the image above.
- [places] is negative. See the formula next to cell C5.
- it requires more than the specified places characters. See the formula next to cell C6.
BIN2HEX returns the #VALUE! error value if places is not a number. See the formula next to cell C7.
The second argument [places]is truncated if it is not an integer. For example, [places] is 4.5 and the BIN2HEX function truncates it to 4. See the formula next to cell C8.
BIN2HEX ignores places and returns a 10-character hexadecimal number if the binary number is negative.
Useful links
BIN2HEX function - Microsoft
Binary to Hex converter
How to Convert Binary to Hexadecimal?
'' function examples
The following article has a formula that contains the function.
Functions in 'Engineering' category
The BIN2HEX function function is one of 42 functions in the 'Engineering' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form