In a book for C# I read that there is direct way to convert from binary to hexadecimal:

  1. convert to nibbles with leading zeros
  2. replace with the hexadecimal representation of the nibble

The rule is divide the binary number into groups containing the number of the power to which we want to convert. 16 = 2 to power 4, so 4 digits.

I tried from base 4 to base 16: 13 33 33 = 7 f f. 4 to the power 2 is 16.

So when the "power" relation is missing (relation is 3/2), is there a way to convert from quaternary (133130) to octal(3734)?

  • $\begingroup$ conversion in binary comes to mind : 11 111 011 100 $\endgroup$ – Raymond Manzoni Mar 21 '12 at 21:37
  • $\begingroup$ I was wandering if this is possible, without binary conversion. $\endgroup$ – Bakudan Mar 21 '12 at 21:42
  • $\begingroup$ Ross' method is fine for powers $p_i$ of the same base here 2 : convert $133_4\to 37_8$ and $130_4\to 34_8$ say using a lookup table with $2^{LCM(p_1,p_2)}$ entries (64 here) if the LCM of the powers is not too high. $\endgroup$ – Raymond Manzoni Mar 21 '12 at 22:41

You can group the digits. As an octal digit accounts for 3 binary bits and a quaternary digit accounts for 2, the LCM of these is 6. So you can take pairs octal digits and convert them to three quaternary digits (like $33_8=123_4$) or vice versa. In a sense, you are going through binary, but in a hidden way. This still depends upon both bases of interest being powers of the same number (here, 2)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.