SUBSTRING() and hex value

我是研究僧i 提交于 2020-01-24 23:42:46

问题


How does substring work on hexadecimal values?

See this:

PRINT SUBSTRING(0x6,1,1)
PRINT SUBSTRING(0xF6,1,1)
PRINT SUBSTRING(0xFF6,1,1)
PRINT SUBSTRING(0xFFF6,1,1)

...outputs...

0x06
0xF6
0x0F
0xFF

...which currently looks as a complete nonsense to me. But it can somehow used in detecting which column is updated in trigger (see COLUMNS_UPDATED()).

I tried:

  • intermediately converted it to string and then substring it
  • intermediately converted it to int, then string and then substring it
  • searching in MSDN substring() documentation
  • googling

Can someone explain how is that conversion done?


回答1:


The SUBSTRING documentation isn't particularly clear about how it treats binary values, referring to 'characters' rather than bytes. But it's effectively treating the input as a byte sequence, and with 1, 1 you are asking for the first byte of the sequence:

Input    Byte sequence
----------------------
0x6      06
0xF6     F6
0xFF6    0F F6
0xFFF6   FF F6

Output of SUBSTRING(input, 1, 1) :

0x06
0xF6
0x0F
0xFF


来源:https://stackoverflow.com/questions/18098798/substring-and-hex-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!