Binary to hex conversion proof

Note that the exponents of 16 will decrease by 1 with each quartet. Also note that the subscripts on the binary digits will decrease by 4 with each quartet.
  • #1
njama
216
1
Hello PF members!

I am interested in proving that the conversion of binary to hex is valid.

Example: 1000100100110111

Breaking into 'quartets' 1000 1001 0011 0111

Now using the fact that 24 = 0...15

1000 = 8, 1001 = 9, 0011 = 3, 0111 = 7. So

10001001001101112=893716

I can create the table starting from 0000 to 1111. I need to prove that this conversion really works.

I would start the proof by stating that the number in binary form is:

[tex]b_1b_2...b_{n-1}b_n[/tex]

If n mod 4 == 0 (if the remainder of the division of n with 4 is zero) then:

[tex]b_1b_2b_3b_4 ... ... ... b_{n-3}b_{n-2}b_{n-1}b_n[/tex]

But how to prove afterward?

else we can add m zeroes so that (m+n) mod 4 ==0.

By adding zeroes before the binary number I can easily prove that nothing is changed.

[tex](*)=b_1b_2...b_{n-1}b_n=b_n*2^0 + b_{n-1}*2^1+...+b_2*2^{n-2}+b_1*2^{n-1}[/tex]

[tex]00..00b_1b_2...b_{n-1}b_n=b_n*2^0 + b_{n-1}*2^1+...+b_2*2^{n-2}+b_1*2^{n-1}+0*2^n+0*2^{n+1}...+0*2^{n+m}=(*)[/tex]

Any help would be appreciated.
 
Mathematics news on Phys.org
  • #2
This is not a proof but an example to show how you might think of it (I reversed the numbering of the coefficients in your example, to match the exponents):

A 12-digit binary number: [tex]b_{11}2^{11}+b_{10}2^{10}+b_{9}2^{9}+b_{8}2^{8}+b_{7}2^{7}+b_{6}2^{6}+b_{5}2^{5}+b_{4}2^{4}+b_{3}2^{3}+b_{2}2^{2}+b_{1}2^{1}+b_{0}2^{0}[/tex]

Factor out multiples of 16: [tex]2^8(b_{11}2^{3}+b_{10}2^{2}+b_{9}2^{1}+b_{8}2^{0})+2^4(b_{7}2^{3}+b_{6}2^{2}+b_{5}2^{1}+b_{4}2^{0})+2^0(b_{3}2^{3}+b_{2}2^{2}+b_{1}2^{1}+b_{0}2^{0})[/tex]

Rewrite with powers of 16: [tex]16^2(b_{11}2^{3}+b_{10}2^{2}+b_{9}2^{1}+b_{8}2^{0})+16^1(b_{7}2^{3}+b_{6}2^{2}+b_{5}2^{1}+b_{4}2^{0})+16^0(b_{3}2^{3}+b_{2}2^{2}+b_{1}2^{1}+b_{0}2^{0})[/tex]

Everything in parentheses is a hex digit, with value 0-15.
 
  • #3
Ohh... Thanks a lot.

Here is what I've done:

(I've excluded the case which I have already proof with the zeroes before the number)

So let's suppose there are m+n+1 digits, and we can form a quartets.

The binary number is:

[tex]b_{m+n}2^{m+n} + b_{m+n-1}2^{m+n-1} + ... + b_32^3+b_22^2+b_12^1+b_02^0[/tex]

Now factoring out multiples of 16

[tex]2^{m+n-3}(b_{m+n}2^3+b_{m+n-1}2^2+...+b_{m+n-3}2^0)+...+2^0(b_32^3+b_22^2+b_12^1+b_02^0)[/tex]

There are m+n / 4 hexadecimal digits. Did I do the proof correctly ? (except for minor mistakes)
 
  • #4
That looks pretty good, except I think you need to make it clear that the terms are powers of 16. That will make the notation cumbersome though. For example, [tex]2^{m+n-3}[/tex] would be [tex](2^{4})^{(m+n+1)/4 - 1}[/tex]. Not too pretty, but a cleaner way doesn't come to mind at the moment.
 
  • #5
Try thinking about it this way:

Each more significant binary digit is represented by a 0 or 1 multiplied by a power of 2 that is greater than the previous digit by 1. In other words (sticking with whole numbers), the lowest binary digit can be represented by [tex]b_02^0[/tex]

Remembering, of course that [tex]b_n=0[/tex] or [tex]b_n=1[/tex] for all n.

The next more significant binary digit can be represented by [tex]b_12^1[/tex]

and so on... Then, for any binary number with more than 4 digits, you have: [tex]2^n , 2^{n-1}, ..., 2^3, 2^2, 2^1, 2^0[/tex]

By breaking a large (more than 4 digits) binary number into quartets, and re-assigning them to values of 0..15, you are actually reassigning the appropriate power of 2 (the exponent) for all digits more significant than [tex]b_32^3[/tex]

Obviously, for the 1st quartet (4 least significant bits), which is [tex]b_3b_2b_1b_0[/tex], the value is already correct (there is no reassignment of exponents) and the quartet's value is [tex]b_32^3+b_22^2+b_12^1+b_02^0[/tex]

For the 2nd quartet, [tex]b_7b_6b_5b_4[/tex], you are essentially changing the exponents from [tex]2^7, 2^6, 2^5, and \phantom{1}2^4[/tex] to [tex]2^3, 2^2, 2^1, and\phantom{1}2^0[/tex]
This results in the 2nd quartet having the value [tex]b_72^3+b_62^2+b_52^1+b_42^0[/tex] (The actual value is, of course: [tex]b_72^7+b_62^6+b_52^5+b_42^4[/tex])

What you've done here is subtracted 4 from each of the exponents in the 2nd quartet: [tex]b_72^{7-4}+b_62^{6-4}+b_52^{5-4}+b_42^{4-4}[/tex]

Using one of the laws of exponents: [tex]\frac{X^a}{X^b}=X^{a-b}[/tex], we can show that 2nd quartet as: [tex]b_7\frac{2^7}{2^4}+b_6\frac{2^6}{2^4}+b_5\frac{2^5}{2^4}+b_4\frac{2^4}{2^4}[/tex]

We can then factor out [tex]\frac{1}{2^4}[/tex], resulting in [tex]\frac{1}{2^4}(b_72^7+b_62^6+b_52^5+b_42^4)[/tex]

And, since [tex]2^4=16[/tex], what you've effectively done, is divided the 2nd quartet by 16!

Extending this same technique out to the next quartet, you'll find that you will have divided that quartet by [tex]2^8=16^2[/tex]

Remember also, that each more significant digit in hexidecimal (base 16) is a successively larger power of 16, such that you have
[tex]h_n16^n+h_{n-1}16^{n-1}+...+h_316^3+h_216^2+h_116^1+h_016^0[/tex]
with [tex]h_n[/tex] = 0...9, A..F
 
  • #6
So, for each quartet [tex]Q_n \phantom{0} (n\geqq1)[/tex], you obtain the hex digit by dividing the binary value of the quartet by [tex]16^{n-1}[/tex]
 
  • #7
Thank you for the help all of you.

So do I need to write it like this:

[tex]
16^{(m+n-3)/4)}(b_{m+n}2^3+b_{m+n-1}2^2+...+b_{m+n-3}2^0)+16^{(m+n-3)/4 -1}(b_{m+n-4}2^3+...+b_{m+n-7}2^0)...+16^0(b_32^3+b_22^2+b_12^1+b_02^0)
[/tex]
 
  • #8
njama said:
Hello PF members!

I am interested in proving that the conversion of binary to hex is valid.

Example: 1000100100110111

Breaking into 'quartets' 1000 1001 0011 0111
Of course 100002= 16 so while 01112= (01112)(1)= (01112)(160)= 7(160), the second set, "00112", is (00112)(16)= (00112)(161)= 3(161, the third "10012 is (10012)(162)= 9(162), and the fourth "10002" is (10002)(163)= 7(163.


Now using the fact that 24 = 0...15

1000 = 8, 1001 = 9, 0011 = 3, 0111 = 7. So

10001001001101112=893716

I can create the table starting from 0000 to 1111. I need to prove that this conversion really works.

I would start the proof by stating that the number in binary form is:

[tex]b_1b_2...b_{n-1}b_n[/tex]

If n mod 4 == 0 (if the remainder of the division of n with 4 is zero) then:

[tex]b_1b_2b_3b_4 ... ... ... b_{n-3}b_{n-2}b_{n-1}b_n[/tex]

But how to prove afterward?

else we can add m zeroes so that (m+n) mod 4 ==0.

By adding zeroes before the binary number I can easily prove that nothing is changed.

[tex](*)=b_1b_2...b_{n-1}b_n=b_n*2^0 + b_{n-1}*2^1+...+b_2*2^{n-2}+b_1*2^{n-1}[/tex]

[tex]00..00b_1b_2...b_{n-1}b_n=b_n*2^0 + b_{n-1}*2^1+...+b_2*2^{n-2}+b_1*2^{n-1}+0*2^n+0*2^{n+1}...+0*2^{n+m}=(*)[/tex]

Any help would be appreciated.
 
  • #9
Ok, I believe to makes things better I should use m+n-1 = 4k
 
  • #10
njama said:
Ok, I believe to makes things better I should use m+n-1 = 4k

I would simplify things a little by first stating that any number (binary, or otherwise) can be led with any number of 0's and still retain the same value. That said, I would FIRST add the number of 0's needed (one, two, or three of them) to make the number of binary digits (bits) evenly divisible by 4. Then use "n" to represent the total number of bits in the binary number (including those added 0's, if any).

Then, you can write it as:

[tex]16^{\frac{n}{4}-1}(b_n2^3 + b_{n-1}2^2 + b_{n-2}2^1 + b_{n-3}2^0) + 16^{\frac{n}{4}-2}(b_{n-3}2^3 + b_{n-4}2^2 + b_{n-5}2^1 + b_{n-6}2^0) + ... + 16^1(b_72^3 + b_62^2 + b_52^1 + b_42^0) + 16^0(b_32^3 + b_22^2 + b_12^1 + b_02^0)[/tex]
 

Related to Binary to hex conversion proof

1. How do you convert binary to hex?

Binary and hexadecimal are both number systems used in computing. To convert binary to hex, you need to group the binary digits into sets of four and then convert each set into its hexadecimal equivalent. For example, 1101 in binary becomes D in hex. Repeat this process for each set until you have converted the entire binary number.

2. What is the proof that binary to hex conversion is accurate?

The proof that binary to hex conversion is accurate lies in the mathematical principles behind each number system. Binary is a base-2 system and hex is a base-16 system. This means that in binary, there are only two possible digits (0 and 1) while in hex, there are 16 possible digits (0-9 and A-F). The conversion process simply involves representing the same value in a different number system, so the accuracy is guaranteed.

3. Why is binary to hex conversion useful?

Binary to hex conversion is useful in computing because it allows for a more compact representation of binary data. Hexadecimal numbers are shorter than binary numbers and easier for humans to read and understand. They are also commonly used in programming languages as they can represent larger numbers with fewer digits, making coding and debugging more efficient.

4. Can you convert a hex number to binary using the same method?

Yes, you can convert a hex number to binary using the same method of grouping digits into sets of four and converting each set to its binary equivalent. However, instead of converting from binary to hex, you will be converting from hex to binary.

5. Is there a shortcut for converting binary to hex?

Yes, there is a shortcut for converting binary to hex. Instead of grouping the binary digits into sets of four, you can group them into sets of three and then convert each set into its hexadecimal equivalent. This method is faster but may be slightly less accurate as it only works for binary numbers that are multiples of three digits.

Similar threads

  • Topology and Analysis
Replies
3
Views
1K
Replies
1
Views
1K
Replies
2
Views
204
  • Linear and Abstract Algebra
Replies
7
Views
836
  • Math Proof Training and Practice
Replies
10
Views
1K
Replies
1
Views
339
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
844
Replies
1
Views
660
  • Math Proof Training and Practice
Replies
8
Views
1K
Back
Top