Hex to Base64: Encode and Decode Bytes Online

in "Encoding"

Base-64 is basically a way of encoding arbitrary binary data in ASCII text.

Base-64 encoding schemes are commonly used when there is a need to encode binary data (for example, images and audio) that needs to be stored and transferred over media that are designed to deal with textual data.

This is to ensure that the data remains intact without modification during transport.

Base-64 encoding schemes uses A – Z, a – z, and 0 – 9 for the 62 values, and the symbols + (plus) and / (slash).

The = (equal) symbol is used as a padding character.

Base-64 maps 3 bytes (8 * 3 = 24 bits) in 4 characters that span 6-bits (6 *4 = 24 bits).

When the number of bytes to encode is not divisible by three that is, if there are only one or two bytes of input for the last 24-bit block, then extra bytes with value zero is added so there are always three bytes.

For example, a base-64 encoded image: https://kifanga.com/uploads/assets/kifanga.png

iVBORw0KGgoAAAANSUhEUgAAAPwAAABlCAYAAABpwo7sAAAACXBIWXMAAAsSAAALEgHS3X78AAAUrklEQVR4nO2dD3AU133H394/JJ1AEhbG5l84jA0Y6hLr7MbUrT0pdsxAJlgZzEygGXADyrQF4pYY5johHuhccEtiu247YzGJmcSkg92h9rgeMBDbpK3cNKf8IWBJmHAe/htjTv9OEne6285veSuv7u2e3ts/d7fa32dGIO2+3du72+/+fu/3fr/3JFmWCYIg3sCH3zOCeAcUPIJ4CBQ8gngIFDyCeAgUPIJ4CBQ8gngIFDyCeAgUPIJ4CBQ8gngIFDyCeAgUPIJ4CBQ8gngIFDyCeAgUPIJ4CBQ8gngIFDyCeAgUPIJ4CBQ8gngIFDyCeIgAftmlJRqNTiaEBE+u37U1H6qama2ZtFrvAnzZG8/ngxOuEEJS8pqmVqYBgpgAJ7HUIRqNBgkhkUsPfHnm5S+sOMa20CUqr2lq19tBbp6zhhBy+5mVm/6kd/bdL8iSbxLTyJhj8pqmRwz3IggnZbHw0Wh0KiGk7kTLP+40snA6gKWbzG5mzj2DEFLzm7964eVcqGoJ08CYs/KapjsM93JcH7Pls2sCsc84s3LTkp7IopeZBghSItzUhzcUlAoVVg0IS1DswLPMFhuIRqN+sOypO++dBJbd5BkbmC0IY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uyh/ALDijU2/lbkKk3XS9ukoY7jKN3kIP6kquEBn/biJwgopiANJc07HI73k8jv+54lu/pS2gCvUCXU6KgeboNxVOjFHsGpiTFCEdizysLMcfT0rks9c7So9oDceTLXQ7uPxJtZ1Z3LR6LELRrDH3Y7rp2+P1s6HWnmEB/dFZ58rWFFvNGnPMdRS5BhHAXQdBrwzHk69rjotS4auBzMV2vJ9x49IjCF2jzlWE48luQgjkSXyLXrey9jwdIjxLF8AgdP8bVt8bWnhkPKGXKu0GIPr+LozDh+PJdTRgBw8DsPKEjs8vptF6S6DgkfEEt+DtnrrLCuF48r10LALj7ZBg8xEhZB8N0j1MI/MwHr+ORustgS49UjHAuLNahLJg/jzITefOSxedAMPuqbusQsfbF2sScN6lgod+/eKC/r1pMEqPVAx0tRdF8H1Z8k8/v+x7j6aswlxx/UYRcNp3PypSmgoTT6q/w8STTINxCrr0SCUxMu4+MUg2L5+V37xsZkYZ/oJtW5be+W9HLvg+ok16Es2ZxXS4TiiHolyzzVQCnhF8OBwOw38Fm6FvFGIac5xO51yl4KrJ10jp3NipdDpd8Tc7lKLOqpWVev74/cNb4/czTYQpwXp5FYuXLHy9gctnVvQqNQ6L/xPN77cye8cmbdACijy6ma0eQJv7XmTZ6XGJZwSfTqcvEkIuMjuQSqIky26rtesU3Qy78QpG6RFPMTBM2jSzzgqnwrodFDziKX59zbdX8365V4oZL6DgkUrC0VLe6zekA5qCmR6jgpnxDAoe8QQwG86jbwV30Pc61NHZVZaJ+8oNCh4Z90DN/INvhJrp+4S14M559VvHTDukoqDLRq2iZa6WVvoFq366W2p98njwMB1vT3V0dvUxDT0ECh6peNKxyEY1h6IvS6omBonh3G5gzWGcnU5M8b90nN1z0XgjUPAI4iGwD48gHgIFjyAeAgWPIB4CBY8gHgIFjyAeAgWPIB4CBY8gHgIFjyAeAgWPIF6BEPL/qcsdBXImFLIAAAAASUVORK5CYII=

How to convert hex to base-64

For example, base-64 encode the word “Cat”.

ASCII text conversion table:

ASCII


Hex


Symbol


0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F

NUL
SOH
STX
ETX
EOT
ENQ
ACK
BEL
BS
TAB
LF
VT
FF
CR
SO
SI


ASCII


Hex


Symbol


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

10
11
12
13
14
15
16
17
18
19
1A
1B
1C
1D
1E
1F

DLE
DC1
DC2
DC3
DC4
NAK
SYN
ETB
CAN
EM
SUB
ESC
FS
GS
RS
US


ASCII


Hex


Symbol


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

20
21
22
23
24
25
26
27
28
29
2A
2B
2C
2D
2E
2F

(space)
!
"
#
$
%
&
'
(
)
*
+
,
-
.
/


ASCII


Hex


Symbol


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

30
31
32
33
34
35
36
37
38
39
3A
3B
3C
3D
3E
3F

0
1
2
3
4
5
6
7
8
9
:
;
<
=
>
?


ASCII


Hex


Symbol


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

40
41
42
43
44
45
46
47
48
49
4A
4B
4C
4D
4E
4F

@
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O


ASCII


Hex


Symbol


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

50
51
52
53
54
55
56
57
58
59
5A
5B
5C
5D
5E
5F

P
Q
R
S
T
U
V
W
X
Y
Z
[
\
]
^
_


ASCII


Hex


Symbol


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

60
61
62
63
64
65
66
67
68
69
6A
6B
6C
6D
6E
6F

`
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o


ASCII


Hex


Symbol


112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

70
71
72
73
74
75
76
77
78
79
7A
7B
7C
7D
7E
7F

p
q
r
s
t
u
v
w
x
y
z
{
|
}
~


 

Cat in ASCII decimal values = [67, 97, 116].

“Cat” in binary format = [01000011, 01100001, 01110100].

If the data you have is in hexadecimal, you will have to convert hex to binary before you can convert hex to base-64.

After you convert your hex values to binary, the process is as follows:

Step 1. Join the 3 bytes into a 24-bit string.

Group = [01000011 01100001 01110100].

Step 2. Create group of 6-bits from the 24-bit string.

Group = [010000 110110 000101 110100].

Step 3. Convert binary to decimal.

Decimal values = [16, 54, 5, 52].

Step 4. In the base-64 symbol chart, map each decimal value to its corresponding character.

Group = [Q2F0].

Base-64 symbol chart

The BASE64 Alphabet

Char.

Dec.

Hex.

 

Char.

Dec.

Hex.

 

Char.

Dec.

Hex.

A

0

00

 

W

22

16

 

s

44

2C

B

1

01

 

X

23

17

 

t

45

2D

C

2

02

 

Y

24

18

 

u

46

2E

D

3

03

 

Z

25

19

 

v

47

2F

E

4

04

 

a

26

1A

 

w

48

30

F

5

05

 

b

27

1B

 

x

49

31

G

6

06

 

c

28

1C

 

y

50

32

H

7

07

 

d

29

1D

 

z

51

33

I

8

08

 

e

30

1E

 

0

52

34

J

9

09

 

f

31

1F

 

1

53

35

K

10

0A

 

g

32

20

 

2

54

36

L

11

0B

 

h

33

21

 

3

55

37

M

12

0C

 

i

34

22

 

4

56

38

N

13

0D

 

j

35

23

 

5

57

39

O

14

0E

 

k

36

24

 

6

58

3A

P

15

0F

 

l

37

25

 

7

59

3B

Q

16

10

 

m

38

26

 

8

60

3C

R

17

11

 

n

39

27

 

9

61

3D

S

18

12

 

o

40

28

 

+

62

3E

T

19

13

 

p

41

29

 

/

63

3F

U

20

14

 

q

42

2A

 

 

 

 

V

21

15

 

r

43

2B

 

=

(pad)

(pad)

BASE64 characters are 6 bits in length. They are formed by taking a block of three octets to form a 24-bit string, which is converted into four BASE64 characters.

NOTE: The pad character (=) does not have a binary representation in BASE64; it is inserted into the BASE64 text as a placeholder to maintain 24-bit alignment.

NOTE: In the URL and Filename safe variant, character 62 (0x3E) is replaced with a "-" (minus sign) and character 63 (0x3F) is replaced with a "_" (underscore).

When converting to binary, remember to use only 6 bits (e.g., 0x19 = binary 01 1001).

Above is the base-64 symbol chart.

Lookup the decimal value in the chart and find its corresponding character in the map.

Decimal values: 16, 54, 5, 52 corresponds to: Q2F0.

Thus, the word “Cat” base-64 encoded: Q2F0.

Another example with padding

For example, base-64 encode the word “Hi”.

Step 1. Convert each character to ASCII decimal value.

Hi in ASCII decimal values = [72, 105].

Step 2. Convery the decimal value to binary.

“Hi” in binary format = [01001000, 01101001].

Add extra byte with value zero so there are always three bytes.

Group = [01001000, 01101001, 00000000].

Step 3. Join the 3 bytes into a 24-bit string.

Group = [01001000 01101001 00000000].

Step 4. Create group of 6-bits from the 24-bit string.

Group = [010010 000110 100100 000000].

Step 5. Convert binary to decimal.

Decimal values = [18, 6, 36, 0].

Step 6. In the base-64 symbol chart, map each decimal value to its corresponding character.

Because with have added an extra byte, the 0 is mapped to the = sign symbol.

Group = [SGk=].

Thus, the word “Hi” base-64 encoded: SGk=.

Use the above hex to base64 converter and smart tool which is able to convert online hex values to base64 strings. The tool accepts several written representations of hexadecimal values.

The conversion process is quite simple: the converter decodes the hex values into the original data, then encodes it to base64 and gives you the final result instantly.

Recommended Tools