T
T
Timofey Yatsenko2014-09-24 16:59:49
MySQL
Timofey Yatsenko, 2014-09-24 16:59:49

How to make MySql consider the text value of a HEX column as a number?

The essence of the task: it is necessary to compare two HEX values ​​bit by bit, one comes from php, the second lies in the database in text form. The problem is that it is not possible to pull out the second value as a HEX number, only as a string. The first number is "pasted" into the request on the php side like this "SELECT hash ^ 0x".$hash." FROM...." and there are no problems with this.
How to make MySql consider the text value of a HEX column as a number?
For example, if you make a query with your hands and enter 2 hex there
SELECT 0xd9d8266fd990160f ^ 0xd9d8266fd990160e
, then it will return 1, as expected
.
SELECT 0xd9d8266fd990160f ^ column from table
That returns nonsense, because considers the value of the column not HEX, but string.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Senkevich, 2014-09-24
@thekip

If the hash column contains the string 'd9d8266fd990160f', then try this query:

SELECT CONV(hash, 16, 10) ^ 0xd9d8266fd990160e FROM table

D
Dron Krzh, 2014-09-24
@ walkman7

dev.mysql.com/doc/refman/5.0/en/string-functions.h...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question