Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle: How do I convert hex to decimal in Oracle SQL?

How do I convert hexadecimal to decimal (and back again) using Oracle SQL?

like image 565
Matthew Farwell Avatar asked Aug 04 '09 11:08

Matthew Farwell


People also ask

How do you convert hex to decimal to decimal?

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.

What is hex 7F in decimal?

The below table visualizes how the decimal number 127 equals the hexadecimal number 7F.

How do you convert hex to integer?

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.

How do you change hex to binary?

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.


2 Answers

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; 
like image 67
Petros Avatar answered Sep 17 '22 08:09

Petros


SELECT  TO_NUMBER('DEADBEEF', 'XXXXXXXX') FROM    dual  --- 3735928559  SELECT  TO_CHAR(3735928559, 'XXXXXXXX') FROM    dual ---  DEADBEEF 
like image 30
Quassnoi Avatar answered Sep 20 '22 08:09

Quassnoi