Binary to Hex
Convert binary numbers to hexadecimal notation.
Share on Social Media:
This online Binary to Hexadecimal converter is designed to convert a sequence of bytes in binary format into hexadecimal numbers.
How to Use
Input Text:
- Type or paste the sequence of binary numbers (separated by spaces) you want to convert into the designated input field.
Upload File:
- Alternatively, click on the "Upload File" button to select a text file from your device.
Convert to Hexadecimal:
- Click the "Convert to Hex" button to initiate the conversion process.
View Text Output:
- The resulting sequence of hexadecimal numbers will be displayed in the output area.
Copy to Clipboard:
- Click the "Copy to Clipboard" button to easily copy the hexadecimal numbers.
Save as Text File:
- Click the "Save as TXT" button to download the hexadecimal numbers as a text file to your device.
Binary Number Notation
Binary notation is a base-2 numeral system that uses only two digits: 0 and 1. Each digit in a binary number represents a power of 2. Binary is fundamental in computing and digital electronics, where data is represented using bits (binary digits).
Hexadecimal Number Notation
Hexadecimal notation is a base-16 numeral system that uses 16 digits: 0-9 and A-F (where A=10, B=11, C=12, D=13, E=14, and F=15). Hexadecimal is often used due to its concise representation of binary values. In byte representation, each hexadecimal digit corresponds to four bits (half a byte). Bytes are commonly represented as pairs of hexadecimal digits. Each digit in a hexadecimal number represents a power of 16.To distinguish from decimal numbers, hexadecimals are often prefixed with "0x" or “x”.
Binary to Hexadecimal Conversion
To convert a binary number to hexadecimal, group binary digits into sets of four (starting from the right) and then replace each group with its hexadecimal equivalent.
Example:
Let's convert the binary number 1101101011011011 to hexadecimal.
Separating into groups of 4 bits:
1101 1010 1101 1011
Replacing each group with its hexadecimal equivalent:
D A D B
So, 1101101011011011 is equal to DADB.
Binary to Hexadecimal Conversion in Programming Languages
Here are examples of binary to hexadecimal conversion functions in various programming and scripting languages:
C/C++:
Use strtol to convert binary to decimal and then print the result in hexadecimal using %X.
#include ‹stdio.h ›#include ‹stdlib.h ›int main() { char binaryNumber[] = "1101101011011011"; long decimalNumber = strtol(binaryNumber, NULL, 2); char hexResult[20]; sprintf(hexResult, "%lX", decimalNumber); printf("%s\n", hexResult); // Output: DADB sprintf(hexResult, "%#lX", decimalNumber); printf("%s\n", hexResult); // Output: 0XDADB return 0;}
Edit & run on cpp.sh
Java:
Utilize Integer.parseInt to convert binary to decimal and then format the result in hexadecimal using %X.
public class BinaryToHexadecimal {
public static void main(String[] args) { String binaryNumber = "1101101011011011"; int decimalNumber = Integer.parseInt(binaryNumber, 2); String hexResult = String.format("%X", decimalNumber); System.out.println(hexResult); // Output: DADB
}}
PHP:
Employ bindec for binary to decimal conversion and dechex for hexadecimal formatting.
$binaryNumber = "1101101011011011";$decimalNumber = bindec($binaryNumber);$hexResult = strtoupper(dechex($decimalNumber));echo $hexResult . "\n"; // Output: DADB
Edit & run on OnlinePHP.io
Python:
Use int for binary to decimal conversion and hex for hexadecimal formatting.
binaryNumber = “1101101011011011”decimalNumber = int(binaryNumber, 2)hexResult = hex(decimalNumber)[2:].upper()print(hexResult) # Output: DADB
Edit & run on PythonSanbox.com
Ruby:
Convert binary to decimal using to_i and then format the result in hexadecimal.
binaryNumber = “1101101011011011”decimalNumber = binaryNumber.to_i(2)hexResult = decimalNumber.to_s(16).upcaseputs hexResult # Output: DADB
Edit & run on Try Ruby Playground
JavaScript:
Utilize parseInt for binary to decimal conversion and toString for hexadecimal formatting.
let binaryNumber = "1101101011011011";let decimalNumber = parseInt(binaryNumber, 2);let hexResult = decimalNumber.toString(16).toUpperCase();console.log(hexResult); // Output: DADB
Edit & run on runjs.co
Perl:
Use oct for binary to decimal conversion and sprintf to format the result in hexadecimal.
my $binaryNumber = "1101101011011011";my $decimalNumber = oct("0b$binaryNumber");my $hexResult = sprintf("%X", $decimalNumber);print "$hexResult\n"; # Output: DADB
Edit & run on Tio.run
PowerShell:
Utilize [Convert]::ToInt64 for binary to decimal conversion and ToString for hexadecimal formatting.
$binaryNumber = “1101101011011011”$decimalNumber = [Convert]::ToInt64($binaryNumber, 2)$hexResult = $decimalNumber.ToString("X")Write-Output $hexResult # Output: DADB
Edit & run on Tio.run
Excel/Google Sheet Function for Binary to Hexadecimal Conversion
In Excel or Google Sheets, you can use the BIN2HEX function for binary to hexadecimal conversion.
BIN2HEX(signed_binary_number, [significant_digits])
Where:
- signed_binary_number - the binary number you want to convert. Number cannot contain more than 10 characters (10 bits).
- significant_digits - the number of characters to use. The result will be padded with leading 0s (zeros) if required.
Binary to Hexadecimal Conversion with Windows Calculator
In Windows Calculator, you can perform binary to hexadecimal conversion using the Programmer mode. Here are step-by-step instructions:
- Open the Calculator app on Windows.
- Switch to Programmer mode (click on the "Hamburger" icon and select "Programmer").
- In the Programmer mode at the top left of the calculator screen, select "BIN" for binary.
- Enter your binary number.
- View the hexadecimal result next to the "HEX" option.
- To view the hexadecimal value in the result line click "HEX".