Using hexadecimal as ID in the database

Asked

Viewed 523 times

4

Through the navigation bar, we realize that Google uses hexadecimal values to identify records:

inserir a descrição da imagem aqui

The print above was taken from Gmail, but the same occurs for other services like Google Drive.

  • What is the advantage of using hexadecimal values instead of integers?
  • What kind of column is appropriate in this case: string (sweep), binary, other?
  • 3

    Just one observation, Google does not use a relational database, but Bigtable, a database oriented to http://pt.wikipedia.org/wiki/BigTable

  • 1

    See also on Sopt: How hexadecimal numbers work?

1 answer

6


What is the advantage of using hexadecimal values instead of whole?

Hexadecimal is a slightly shorter representation. For example, the following two values are identical:

999999999 DEX
3B9AC9FF  HEX

You also have a better view of the bit distribution, since each hex position is equivalent to 4 bits:

   3    B    9    A    C    9    F    F   HEX
0011 1011 1001 1010 1100 1001 1111 1111   BIN

Which column type is appropriate in this case: string (varchar), binary, another

Usually numerical, but can be binary. Hexa is just a representation; it is the case of the GUID type, which SQL Server stores as a varbinary(16).

For an example of this type of conversion, see this response in Stack Overflow (English): https://stackoverflow.com/questions/10078209/sql-server-2008-convert-from-guid-to-bigint-and-back

  • I wish I could give more than one positive vote to that reply.

  • So basically Google converts from integer to hexa to mount the URL and then hexa to integer to search for the record in the bank?

  • 1

    @Andrey Think of it this way: An integer is just a set of bytes until someone needs a visualization, which can be decimal, hexadeximal or any other (base 2, base 36, etc.) The hexadecimal representation is closer (and less costly [Citation needed]) of native binary format than decimal. In this sense, you are fully correct - the hexa format is a choice to make available in a URL limited to ASCII characters, for example.

  • I get it, thank you. =)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.