trade off by using Base64 encoding

W

wenmang

Hi,
I ma thinking whether to use Base64 encoding to encode the binary
content in the XML file. I have done some simple calculations, it
seems to me that the size for encoded content increases by ~30%, is
this the drawback for using the encoding scheme?
Thanks.
 
D

Dennis E. Hamilton

By my math, you will use 32 bits for every 24 encoded (4 base64 characters
(bytes) for 3 octets (bytes) worth of bits, or exactly 1-1/3 times the
space required for the raw bits.

Since there's no commonly-available, safe alternative for carrying binary
data in XML elements, I suppose you should be asking "drawback relative to
what?"

(If the binary is compressible, you might do that before Base64 encoding.
But that adds more to what the recipient is required to do.)

-- orcmid
 
W

wenmang

Dennis E. Hamilton said:
By my math, you will use 32 bits for every 24 encoded (4 base64 characters
(bytes) for 3 octets (bytes) worth of bits, or exactly 1-1/3 times the
space required for the raw bits.
I am on HPUX11, could I use 4 base64 chars to encode 4 octets? is this
doable or 1-1/3 ratio is always the case?
Since there's no commonly-available, safe alternative for carrying binary
data in XML elements, I suppose you should be asking "drawback relative to
what?"
I use a wrong word, I should ask "is the price to pay for encoding the
binary content?"
I am wondering whether 1 to 1 byte to byte encoding is possbile using
base64 for binary encoding without incurring the increasing in size?
 
D

Dennis E. Hamilton

In Base 64 encoding, there are only 64 characters used per octet (not
counting white space and other things that don't count). That gives you 6
bits of encoded material. The only way to encode 24 bits of material (3
full octets) is with 4 Base 64 characters. You will always use 4 octets to
encode 3.

The whole reason for this is to be able to use a channel that will likely
preserve those 64 different character encodings, in traveling end-to-end,
without loss or disruption. That's the price. The machine and operating
system you are on has nothing to do with it.

-- orcmid
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top