变换Base64的字符串作为BASE16(HEX)字符串? [英] Transform BASE64 string to BASE16(HEX) string?
问题描述
我试图写一个程序从一个Base64字符串到BASE16(HEX)字符串转换。
Hey, I'm trying to write a program to convert from a BASE64 string to a BASE16(HEX) string.
下面是一个例子:
BASE64: Ba7+Kj3N
HEXADECIMAL: 05 ae fe 2a 3d cd
BINARY: 00000101 10101110 11111110 00101010 00111101 11001101
DECIMAL: 5 174 254 42 61 205
什么是从BASE64转换为十六进制的逻辑是什么?结果
为什么小数重presentation分手了?结果
怎么会二进制重新presentation被分成6部分?
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?
只是想数学中,code我能应付眼前这个过程是混淆了我。感谢:)
Just want the math, the code I can handle just this process is confusing me. Thanks :)
推荐答案
下面是一个功能列表,将任何两个基地之间的转换:的https://sites.google.com/site/computersciencesource$c$c/conversion-algorithms/base-to-base
Here's a function listing that will convert between any two bases: https://sites.google.com/site/computersciencesourcecode/conversion-algorithms/base-to-base
编辑(希望使这个完全清楚...)
Edit (Hopefully to make this completely clear...)
您可以找到在维基百科条目基地64 更多相关信息。
You can find more information on this at the Wikipedia entry for Base 64.
用于基64,这是不是设置你的前编辑我提供的链接找到人物的不同习惯的字符集,方法是:
The customary character set used for base 64, which is different than the character set you'll find in the link I provided prior to the edit, is:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 + /
字符'A'的价值是0,'B'的值为1,C是价值2,......'8'是值60,9是价值61'+ '是值62,和'/'是值63,字符集是从用于使用二进制,八进制,底座10,和十六进制,其中第一个字符是什么我们非常不同的'0',这再presents值0等。
The character 'A' is the value 0, 'B' is the value 1, 'C' is the value 2, ...'8' is the value 60, '9' is the value 61, '+' is the value 62, and '/' is the value 63. This character set is very different from what we're used to using for binary, octal, base 10, and hexadecimal, where the first character is '0', which represents the value 0, etc.
烧酒在评论中指出,以这样的回答,每个基地64位需要6位重新present以二进制。使用原来的问题提供了基本的64号和64基转换为二进制我们得到:
Soju noted in the comments to this answer that each base 64 digit requires 6 bits to represent it in binary. Using the base 64 number provided in the original question and converting from base 64 to binary we get:
B a 7 + K j 3 N
000001 011010 111011 111110 001010 100011 110111 001101
现在我们所有位推合(空格只在那里帮助人类阅读次数):
Now we can push all the bits together (the spaces are only there to help humans read the number):
000001011010111011111110001010100011110111001101
接下来,我们可以引入新的空白分隔符每4位开始用的最低位的:
0000 0101 1010 1110 1111 1110 0010 1010 0011 1101 1100 1101
现在应该很容易看到这个数字是如何转换成16进制:
It should now be very easy to see how this number is converted to base 16:
0000 0101 1010 1110 1111 1110 0010 1010 0011 1101 1100 1101
0 5 A E F E 2 A 3 D C D
这篇关于变换Base64的字符串作为BASE16(HEX)字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!