Z
Z
zeuss562016-10-16 22:43:40
Computer networks
zeuss56, 2016-10-16 22:43:40

What is the optimal HEX -> DOMAIN conversion algorithm?

I call the conversion algorithm , for example, Base64 or Punicode.

You need to compress the IP address to match the following regular expression: (a-z0-9\-)+. I use this to convert IP to domain. For example, this is reduced by at least a couple of characters:, 127.0.0.1 -> 7F.0.0.1but this is not the best option, because not used j-zand "-". How to do this, are there similar algorithms?

If the question "what the x .., what is the IP -> domain ??" is spinning, you are here .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Taratin, 2016-10-16
@zeuss56

127.0.0.1 can be represented as an unsigned byte (0-255) array of 4 elements.
We pack the resulting array into unsigned int32
C++ example

inline uint32_t PACK(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3) {
    return (c0 << 24) | (c1 << 16) | (c2 << 8) | c3;
}

Convert the resulting number to base62
google

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question