Hey, I’m trying to write a program to convert from a BASE64 string to a BASE16(HEX) string.
Here’s an example:
BASE64: Ba7+Kj3N
HEXADECIMAL: 05 ae fe 2a 3d cd
BINARY: 00000101 10101110 11111110 00101010 00111101 11001101
DECIMAL: 5 174 254 42 61 205
What’s the logic to convert from BASE64 to HEXIDECIMAL?
Why is the decimal representation split up?
How come the binary representation is split into 6 section?
Just want the math, the code I can handle just this process is confusing me. Thanks 🙂
Read the base64 4 chars at a time, since 4 base64 chars become 3 bytes:
Decode each char of the base64. I just looked it up on Wikipedia:
Shift the numbers in each group to the left by 18, 12, 6, and 0 respectively:
Then, if you want to convert to hex yourself, shift them to the right by 4, 8, … 24, 28 to peel off each nybble and convert to a digit from 0 to f.