Emergency: Question about function from_bytes and to to_bytes

Database

Emergency: Question about function from_bytes and to to_bytes

Now i want to convert hash column<byte(32)> to base16, just like from_bytes(hash_column,'base16'). but some results are different from that our user coverted using other tool.

take one record  an example:

My result:

from_bytes(hash_column,'base16') -> 

-20CD8BFE2E276DE235DD355F29F55D58B18971EB7B854431F5640F9E0FBDDB74

User result:

DF327401D1D8921DCA22CAA0D60AA2A74E768E14847ABBCE0A9BF061F042248C

but I aslo convert above result from base16 to base, the result is the same.

My result: select  from_bytes('20CD8BFE2E276DE235DD355F29F55D58B18971EB7B854431F5640F9E0FBDDB74'XB, 'base2');

10000011001101100010111111111000101110001001110110110111100010001101011101110100110101010111110010100111110101010111010101100010110001100010010111000111101011011110111000010101000100001100011111010101100100000011111001111000001111101111011101101101110100

User result: select from_bytes('DF327401D1D8921DCA22CAA0D60AA2A74E768E14847ABBCE0A9BF061F042248C'XB, 'base2');

-10000011001101100010111111111000101110001001110110110111100010001101011101110100110101010111110010100111110101010111010101100010110001100010010111000111101011011110111000010101000100001100011111010101100100000011111001111000001111101111011101101101110100

From the result, the base12 result is the same, for my result, just the '-' is not coverted to base16.

Can anyone tell me how to handle the '-' in case my result mathch with user's result?

Tags (1)
1 REPLY
Teradata Employee

Re: Emergency: Question about function from_bytes and to to_bytes

To avoid being treated as negative, just add leading zero byte:

from_bytes('00'xb||hash_column,'base16')