如何在varbinary列的第N个字节上执行二进制操作?
问题描述:
我已经能够与substring(colname, N, 1)
获得的第N个字节出了场,但在这一点上似乎无法治疗的结果为二进制:如何在varbinary列的第N个字节上执行二进制操作?
> select substring(colname, N, 1) from [...]
\
> select hex(substring(colname, N, 1)) from [...]
5C
> select hex(substring(colname, N, 1) & 0xff) from [...]
0
> select cast(substring(colname, N, 1) as unsigned integer) from [...]
0
相比:
> select cast(0x5c as binary);
\
> select hex(0x5c & 0xff);
5C
> select cast(0x5c as unsigned integer);
92
我想直到结束是这样的:
> select [...] where substring(colname, N, 1) & 0b00100000 = 0b00100000;
答
尝试类似的东西:
select ascii(substring(colname,N,1)) from [...]
这个工程,但为什么? – l0b0
你需要你的第N个字符的代码才能使用它。函数ascii(..)返回字符的代码。 –