How to imagine an n-byte array in less than 2 * n characters

given that an n-byte array can be represented as a 2 * n character string using hex, is there a way to represent an n-byte array in less than 2 * n characters?

for example, as a rule, an integer (int32) can be considered as a 4-byte data array

+3
source share
7 answers

The advantage of hex is that splitting an 8-bit byte into two equal halves is the simplest thing you can do to map a byte to printable ASCII characters. More efficient methods treat several bytes as a block:


Base-64 64 ASCII 6 . 3 ( 24 ) 4 6- 64, "":

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

( 3 , 65- , "=", ). , base-64, .


Ascii85 - , , : PostScript PDF. 4 (big-endian) , 5- 85, -85 ASCII- 33 + n (.. "!" 0, "u" 84) - , "z" ( "!!!!!" ) 4 .

( 85? 84 5 < 2 32 < 85 5.)

+8

, ( n , ) 16, 64.

+4

, . , 9223372036854775808, 8 , 4 ascii, ( "2 ^ 63" ).

+2

base-64?

, (.. ).

+1

Base64 6 , , 3 4 .

+1

Using 65536 of approximately 90,000 specific Unicode characters, you can represent a binary string in N / 2 characters.

+1
source

Yes. Use more characters than just 0-9 and af. One character (presumably 8 bits) can have 256 values, so you can represent an n-byte number in n characters.

If necessary for printing, you can simply select a character set to represent different values. A good option is base-64 in this case.

0
source

Source: https://habr.com/ru/post/1770204/


All Articles