Converts a sequence of alphanumeric characters to their equivalent hexadecimal digits.
select strtobin(“string of valid alphanumeric characters”)
select strtobin("723ad82fe") go
----------------------------------- 0x0723ad82fe
The in-memory representation of the alphanumeric character string and its equivalent hexadecimal digits are:
Alphanumeric character string (9 bytes) |
|||||||||||||||||||
0 |
7 |
2 |
3 |
a |
d |
8 |
2 |
f |
e |
||||||||||
Hexadecimal digits (5 bytes) |
|||||||||||||||||||
0 |
7 |
2 |
3 |
a |
d |
8 |
2 |
f |
e |
The function processes characters from right to left. In this example, the number of characters in the input is odd. For this reason, the hexadecimal sequence has a prefix of “0” and is reflected in the output.
declare @str_data varchar(30) select @str_data = "723ad82fe" select strtobin(@str_data) go
---------- 0x0723ad82fe
Any invalid characters in the input results in NULL as the output.
The input sequence of hexadecimal digits must have a prefix of “0x”.
A NULL input results in NULL output.
ANSI SQL – Compliance level: Transact-SQL extension.
Any user can execute strtobin.