|
|
Archives of the TeradataForum
Message Posted: Tue, 12 Aug 2003 @ 20:43:11 GMT
Subj: | | Re: How to convert decimal to hex |
|
From: | | Geoffrey Rommel |
| I am trying to convert decimal value to Hexadecimal. I didn't see any function in Teradata to do that. | |
By "decimal", do you mean any number expressed in decimal digits? integers only? decimal(p,s) numbers only? positive, negative, or
both? By "hexadecimal", do you mean the actual internal representation of a numeric field, or a generated version? big or little endian?
The following expression will generate a big-endian hexadecimal representation for positive integers only (up to 32 bits). This could be
extended to negative integers without too much trouble.
sel ident0,
substr('0123456789ABCDEF', (ident0 / 268435456)+1, 1) ||
substr('0123456789ABCDEF', (ident0 / 16777216 MOD 16)+1, 1) ||
substr('0123456789ABCDEF', (ident0 / 1048576 MOD 16)+1, 1) ||
substr('0123456789ABCDEF', (ident0 / 65536 MOD 16)+1, 1) ||
substr('0123456789ABCDEF', (ident0 / 4096 MOD 16)+1, 1) ||
substr('0123456789ABCDEF', (ident0 / 256 MOD 16)+1, 1) ||
substr('0123456789ABCDEF', (ident0 / 16 MOD 16)+1, 1) ||
substr('0123456789ABCDEF', (ident0 MOD 16)+1, 1)
from testints
where ident0 >= 0;
If you want to do anything more complex, such as mapping decimal numbers to their internal representations, you will have to build
a conversion table, I believe.
| |