Y = base64(X) where X is integer - is Y alphanumeric?
Additional details:
- X is any positive integer 6 digits or less.
- X is left-padded with zer开发者_StackOverflow中文版os to maintain a width of 6.
Please explain your answer :)
(This might be better in the Math site, but figured it involves programming functions)
The picture from the german Wikipedia article is very helpful:
You see that 6 consecutive bits from the original bytes generate a Base64 value. To generate +
or /
(codes 62 and 63), you'd need the bitstrings 111110
and 111111
, so at least 5 consecutive bits set.
However, look at the ASCII codes for 0
...9
:
00110000
00110001
00110010
00110011
00110100
00110101
00110110
00110111
00111000
00111001
No matter how you concatenate six of those, there won't be more than 3 consecutive bits set. So it's not possible to generate a Base64 string that contains +
or /
this way, Y will always be alphanumeric.
EDIT: In fact, you can even rule other Base64 values out like 000010
(C
), so this leads to nice follow-up questions/puzzles like "How many of the 64 values are possible at all?".
精彩评论