How do I convert hexadecimal to decimal (and back again) using Oracle SQL?
The conversion of hexadecimal to decimal is done by using the base number 16. The hexadecimal digit is expanded to multiply each digit with the power of 16. The power starts at 0 from the right moving forward towards the right with the increase in power. For the conversion to complete, the multiplied numbers are added.
The below table visualizes how the decimal number 127 equals the hexadecimal number 7F.
To convert a hexadecimal to a decimal manually, you must start by multiplying the hex number by 16. Then, you raise it to a power of 0 and increase that power by 1 each time according to the hexadecimal number equivalent.
Hexadecimal to binary Split the hex number into individual values. Convert each hex value into its decimal equivalent. Next, convert each decimal digit into binary, making sure to write four digits for each value. Combine all four digits to make one binary number.
If you are using 8.1.5 and above you can use:
To convert from hexadecimal to decimal:
select to_number('AA', 'xx') from dual;
To convert from decimal to hexadecimal:
select to_char(111, 'xxxx') from dual;
SELECT TO_NUMBER('DEADBEEF', 'XXXXXXXX') FROM dual --- 3735928559 SELECT TO_CHAR(3735928559, 'XXXXXXXX') FROM dual --- DEADBEEF
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With