How to convert Binary to Hexadecimal?
Last Updated :
01 Oct, 2024
Number Systems are a major part of mathematics. The number system and its conversions are used in the various fields of mathematics and computer science. The binary number system is a system in which numbers are expressed in the base 2.
This article is about the binary, hexadecimal, and conversion of binary to the hexadecimal number system. The binary-to-decimal conversion is very easy and is explained further.
| Decimal |
Binary |
| 0 |
0000 |
| 1 |
0001 |
| 2 |
0010 |
| 3 |
0011 |
| 4 |
0100 |
| 5 |
0101 |
| 6 |
0110 |
| 7 |
0111 |
| 8 |
1000 |
| 9 |
1001 |
| 10 |
1010 |
The hexadecimal number system is a system in which numbers are expressed in the base 16. In the hexadecimal number system, the numbers are represented in terms of 0-9 and A – F. The hexadecimal number is written as number H, (number)16, (number)H. Example: (A23F)16,
| Decimal |
Hexadecimal |
| 0 |
0 |
| 1 |
1 |
| 2 |
2 |
| 3 |
3 |
| 4 |
4 |
| 5 |
5 |
| 6 |
6 |
| 7 |
7 |
| 8 |
8 |
| 9 |
9 |
| 10 |
A |
Conversion of Binary to Hexadecimal
Method 1
- Firstly, convert the given binary number into decimal.
- Then, convert the obtained decimal into hexadecimal.
Example: (1110)2 = (_______)16
First convert (1110)2 into decimal = (1110)2 = 23 Ã 1 + 22 Ã 1 + 21 Ã 1 + 20 Ã 0 = 8 + 4 + 2 + 0 = (14)10
Then, convert (14)10 into hexadecimal = (14)10 = (E)16
Example 2 : (0.11001)2 = (_________)16
First convert (0)2 to decimal = 0*20 = (0)10
Then convert (11001)2 to decimal = 1*2-1 + 1*2-2 + 0*2-3 + 0*2-4 + 1*2-5 = (0.78125)10
Now, convert (0)10 into hexadecimal = (0)16
Now convert (.78125)10 to hexadecimal
0.78125*16 = 12.5
0.5*16 = 8.0
(.78125)10 to hexadecimal = (.C8)16
where C for 12 and 8 for 8
So (0.11001)2 = (0.C8)16
Method 2: (Direct Method for converting binary to hexadecimal)
Take the given binary number and form the collection of four bits called a quad, then replace the quad with its hexadecimal equivalent. Hence, the obtained number is the conversion of a given binary to hexadecimal.
Note
- If, while forming the quad, the bits are before the radix point, then start forming the quad from the LSB bit and if the bits are after the radix point, start forming the quad from the immediate bit after the radix point.
- While forming the quad, the number of bits is less than 4 and before the radix point, then add 0s before the fewer bits to form a quad.
- While forming the quad, the number of bits is less than 4 and after the radix point then, add 0s after the fewer bits to form a quad.
| Decimal |
Binary |
Hexadecimal |
| 0 |
0000 |
0 |
| 1 |
0001 |
1 |
| 2 |
0010 |
2 |
| 3 |
0011 |
3 |
| 4 |
0100 |
4 |
| 5 |
0101 |
5 |
| 6 |
0110 |
6 |
| 7 |
0111 |
7 |
| 8 |
1000 |
8 |
| 9 |
1001 |
9 |
| 10 |
1010 |
A |
Example: (11101111.111001)2 = (_______)16
| 1110 1111.1110 01 |
| 1110 1111 |
1110 0100 |
| E F |
E 4 |
| (11101111.111001)2 = (EF.E4)16 |
We added two zeros at the last as we have only 01, which does not make a quad. 0s are added after 01 because it is after the radix point.
Sample Questions
Question 1: Convert: (111111101)2 = (_________)16
Solution:
(111111101)2 = 0001 1111 1101 (The bold three 0s are added before 1 as it is integral part (before the radix point))
= 1 F D
= (111111101)2 = (1FD)16
Question 2: Convert: (01011110001)2 = (_________)16
Solution:
(01011110001)2 = 0010 1111 0001 (The bold one 0s are added before 1 as it is integral part (before the radix point))
= 2 F 1
= (01011110001)2 = (2F1)16
Question 3: Convert: (0.11001)2 = (_________)16
Solution:
(0.11001)2 = 0000 . 1100 1000 (The bold three 0s are added before 0 as it is an integral part (before the radix point), and 3 bold 0s are added after 1 as 1 is after the radix point).
= 0 C 8
(0.11001)2 = (0.C8)16
Question 4: Convert: (1.1)2 = (_______)16
Solution:
(1.1)2 = 0001 . 1000 (The bold three 0s are added before 1 as it is an integral part (before the radix point), and 3 bold 0s are added after 1 as 1 is after the radix point).
= 1 8
= (1.1)2 = (1.8)16
Conclusion
Converting binary to hexadecimal is a simple process that utilizes grouping and direct conversion through the lookup table. This method is efficient and commonly used in the computing and digital electronics due to the compact nature of hexadecimal representation compared to binary.
FAQs on Binary to Hexadecimal Conversion
Why do we use hexadecimal in computing?
The Hexadecimal is more compact than binary and easier for humans to read and write. Each hexadecimal digit represents four binary digits making it a shorthand for the binary data.
Can you convert binary to hexadecimal without grouping?
No, grouping is essential for accurate conversion. Each group of four binary digits directly corresponds to the single hexadecimal digit.
What if the binary number has fewer than four digits?
If there are fewer than four digits simply add leading zeros to the left until the group has four digits.
Similar Reads
Merge two matrices by row names in R
In this article, we will examine various methods to merge two matrices by row names in the R programming language. What is a matrix?A matrix is defined as it is a two-dimensional data set which is the collection of rows and columns. A matrix can have the ability to contain or accept data of the same
4 min read
Evaluate Einstein's summation convention of two multidimensional NumPy arrays
In Python, we can use the einsum() function of the NumPy package to compute Einstein's summation convention of two given multidimensional arrays. Syntax: numpy.einsum(subscripts, *operands, out=None) Parameters: subscripts : str Specifies the subscripts for summation as comma separated list of subsc
3 min read
JavaScript Program to Add Two Matrices
Given two N x M matrices. Find a N x M matrix as the sum of given matrices each value at the sum of values of corresponding elements of the given two matrices In this article, we will see how we can perform the addition of two input matrices using JavaScript. Example: Table of ContentUsing Loop in J
3 min read
CopyOnWriteArrayList addAll() method in Java with Examples
boolean addAll(Collection c) This method is used to append all the elements identified by the collection c at the end of the list, in the same order returned by the collection's iterator. Parameters: This method accepts a mandatory parameter c which is the collection containing the elements, which a
4 min read
Convert a matrix into a lower triangular matrix using R
In this article, we will explore various methods to convert a matrix into a lower triangular matrix in R programming language. What is a matrix?A matrix is a two-dimensional rectangular data structure, which is a collection of rows and columns. Representation of rows is horizontal and columns are ve
5 min read
How to read a Matrix from user in Java?
Given task is to read a matrix from the user. The size and number of elements of matrices are to be read from the keyboard. // Java program to read a matrix from user import java.util.Scanner; public class MatrixFromUser { // Function to read matrix public static void readMatrixByUser() { int m, n,
2 min read
Operations on Matrices in R
Matrices in R are a bunch of values, either real or complex numbers, arranged in a group of fixed number of rows and columns. Matrices are used to depict the data in a structured and well-organized format. It is necessary to enclose the elements of a matrix in parentheses or brackets. A matrix with
8 min read
Matrix in R - Arithmetic Operations
Arithmetic operations include addition (+), subtraction (-), multiplication(*), division (/) and modulus(%). In this article we are going to see the matrix creation and arithmetic operations on the matrices in R programming language. ApproachCreate first matrix Syntax: matrix_name <- matrix(data
3 min read
How to Find Percentage of Similarity Between Two Matrices in MATLAB?
MATLAB is a high-performance language that is used for matrix manipulation, performing technical computations, graph plottings, etc. It stands for Matrix Laboratory. With the help of this software, we can find how many elements are the same in two matrices and also calculate the percentage of simila
2 min read
Append a row to a matrix using R
In this article, we will examine various methods to append a row into a matrix in the R Programming Language. What is a matrix?A matrix is a two-dimensional data set, which is a collection of rows and columns. It contains n rows and m columns. Inside the matrix, rows are arranged horizontally and co
4 min read
Matrices and Matrix Arithmetic for Machine Learning
In machine learning, the data often comes in multi-dimensional arrays so matrices are best to handle such inputs. So we need to have some general idea on basic arithmetic operations in matrices. In this article, we will discuss about matrices and matrix arithmetic for machine learning. What is a Mat
6 min read
How to Create a Matrix From a Nested Loop in MATLAB?
Matrices are 2-dimensional arrays that store numeric or symbolic data. It is convenient to create them with the help of nested loops as the outer loop creates the elements along one dimension and the inner loop creates the elements along the second dimension. In this article, we will see how to crea
2 min read
How to Use Swing Applet in Java?
In this article, we will be using the swing Applet or JApplet in Java. Here, we will make a simple multiplication application that will multiply the two input numbers. Approach to Using Swing Applet in JavaWe need to import the packages for Swing and AWT Components.Once the packages are imported, we
4 min read
How to Create a New Matrix From All Possible Row Combinations in MATLAB?
A matrix represents a collection of numbers arranged in an order of rows and columns. A matrix encloses the elements in parentheses or brackets. We will learn how to create a new matrix from all possible row combinations of rows of a different matrix and display the combinations. Procedure of Making
3 min read
Elementary Operations on Matrices
Elementary Operations on Matrices are the operations performed on the rows and columns of the matrix that do not change the value of the matrix. A matrix is a way of representing numbers in the form of an array, i.e. the numbers are arranged in the form of rows and columns. In a matrix, the rows and
9 min read
Strassen algorithm in Python
Strassen's algorithm is an efficient method for matrix multiplication. It reduces the number of arithmetic operations required for multiplying two matrices by decomposing them into smaller submatrices and performing recursive multiplication. Strassen's algorithm is based on the divide-and-conquer ap
3 min read
How to Find Multiplication of Two Matrices of any Size in PHP?
Multiplying two matrices is a common operation in linear algebra. To multiply two matrices of any size in PHP, you can create a function that takes two matrices as input and returns their product. Below are the approaches to find the Multiplication of two Matrices of any size in PHP: Table of Conten
4 min read
Practice Questions on Subtraction of Matrices
Subtraction of Matrices is one of the operations that are performed between two matrices. It is similar to addition of matrices. This article provides practice questions on subtraction of matrices along with solved examples and concepts related to it. This article serves as a one stop solution for p
11 min read
Addition of Matrices Worksheet : Solved and Unsolved
Addition of Matrices Worksheet will help students grasp the concept of matrix addition, improve their problem-solving skills, and prepare them for more advanced topics in mathematics. Matrices are a fundamental concept in mathematics, particularly in linear algebra. They are rectangular arrays of nu
10 min read