I'm looking for a datatype in SQL Server that stores data as hexadecimal rather than int, but can't find anything similar. Surely there is a hexadecimal datatype?
HEX() function MySQL HEX() returns a string representation of a hexadecimal value of a decimal or string value specified as an argument. If the argument is a string, each character in the argument is converted to two hexadecimal digits.
Hexadecimal notation Integers are sometimes written or entered in base 16, known as hexadecimal or just "hex". Hex uses the standard digits 0 thru 9 plus letters A thru F . When hex notation is used to enter or display an integer value in Analytica, it is always preceded with 0x , as in these examples: 0x25 = 37.
Binary, Varbinary & Varbinary(max) are the binary string data types in SQL Server. These data types are used to store raw binary data up to a length of (32K – 1) bytes.
VARBINARY: A variable-width string up to a length of max-length bytes, where the maximum number of bytes is declared as an optional specifier to the type. The default is the default attribute size, which is 80, and the maximum length is 65000 bytes. VARBINARY values are not extended to the full width of the column.
Store it as an INT
and use the HEX()
function to convert it.
There's no native storage for hexadecimal in SQL Server.
EDIT:
You can also store hex data as VARBINARY
, but there is still a conversion required, and there are data integrity issues with that method as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With