Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
peter_turner
Partner - Specialist
Partner - Specialist

Hexadecimal to Decimal, how?

Hello,

Real simple question, but how do you convert a HEX value to a Decimal value in QV?

E.g

Hex E0 should be Decimal 224

I know i can do this the other way around and convert decimal to hex with num(224,'(hex)'), but not the other way around.

Thanks for your input!

1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP


PeterAtMAC wrote: Real simple question, but how do you convert a HEX value to a Decimal value in QV?


How about:

=num(num#('E0','(HEX)'))

-Rob

View solution in original post

10 Replies
Not applicable

Can you do it in your load script or does it need to be a QlikView function?

In PLSQL, you could use: CONVERT(Field, INT, 0xFFFFFF) or Val("&h" & Field). I wasn't able to test these as I don't have any tables with hex values. I'm guessing there are similar methods in TSQL.

As for QlikView, it seems like you should be able to do it using the num function. To convert to a decimal, you would use: Num(Value, '(R10)'). Unfortunately, that function doesn't like it when you use letters in the value. The function can convert from hex to decimal though as you can see by doing something like: Num(Num(224, '(hex)'), '(R10)'). This will result in 224, so the function is converted to hex and back using only the Num function.

peter_turner
Partner - Specialist
Partner - Specialist
Author

Thanks for the reply, have a hex value is causeing me trouble also.

When i set my 'value' as E0 it just stops.

I can do this converstion during my load script or after, either is ok for this project.

I'm suprised there is'nt a function like Dec2Hex or similar, i might end up making a lookup table with 255 rows of data with the hex value from 00 to FF and its decimal equivelant.

Not applicable

Are you loading from a QVD or straight from a database?

I am also surprised that there is not a function, probably more surprised that the Num function doesn't seem to work as that seems to be the way to do it.

A lookup table is a pretty good idea, as it would be a one time thing. You could probably download a list somewhere, so you wouldn't need to manually build it. Although, it may get tricky if you have values greater than 255.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP


PeterAtMAC wrote: Real simple question, but how do you convert a HEX value to a Decimal value in QV?


How about:

=num(num#('E0','(HEX)'))

-Rob

Not applicable

Nice, that does it. So you're converting a string to a hex and then a hex to the integer. I tried the Num#, but when it gave me E0, I thought it wasn't working.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

It's a good exercise to understand the subtlties of internal numbers and external representation.

The num#() function allows the E0 string number to be read correctly as a hexadecimal number. At this point it is "converted". That is, it is stored internally as a number. It can be used in arithmetic.

The default output format is still HEX. The num() function changes the display format to decimal, but doesn't change the internal representation of the number.

It's useful to know that the default output of an expression will be decimal. So all of these will display as decimal 224:

=num#('E0','(HEX)')+0
=floor(num#('E0','(HEX)'))

-Rob

hector
Specialist
Specialist

Hi, i made a simple function to do this conversion just for fun Wink

Can you test with your data?

Regards

wizardo
Creator III
Creator III

hi

if i understand correctly then after using the num# i get qlikview to store the string as number

but does it store it as decimal number? i am not talking about the format

i have a string that contains hexa numbers (2 digit numbers) that i need to convert each pair into decimal and then use this number with the chr() function to find the corresponding ascii letter

when i use format option to convert the number to dec it does not pass a dec value to the chr() function because inside its still kept as hexa

am i correct?

is there a work around?

thanks

Mansyno

hansdevr
Creator III
Creator III

Thnx, Hector! Although it's almost 7 years old, your post came in very handy!!