# QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Announcements
Customers, Partners & Luminaries only: You're invited to a Data Analytics Roadmap session. Read More
cancel
Showing results for
Did you mean:
Highlighted
Partner

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.

1 Solution

Accepted Solutions
Highlighted
MVP & Luminary

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

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

-Rob

10 Replies
Highlighted
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.

Highlighted
Partner

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.

Highlighted
Not applicable

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.

Highlighted
MVP & Luminary

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

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

-Rob

Highlighted
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.

Highlighted
MVP & Luminary

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

Highlighted
Specialist

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

Can you test with your data?

Regards

Highlighted
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

Highlighted
Creator III

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