Qlik Community

QlikView Documents

Documents for QlikView related information.

Conversion of Binary Numbers to Decimal Numbers in Scripting

MVP
MVP

Conversion of Binary Numbers to Decimal Numbers in Scripting

Hi All,

I hope this script helps you when you require to convert Binary numbers to Decimal numbers.

Table: 

LOAD Binary, Sum(DecimalValue) AS Decimal 

GROUP BY Binary; 

LOAD Binary,

  Alt(Pow(If(Mid(Binary, IterNo(), 1) = 1, 2), Len(Binary)-IterNo()), 0)  AS DecimalValue

While Iterno() <= Length; 

LOAD Text(Binary) AS Binary, 

    Len(Binary) AS Length

Inline [ 

Binary 

1011

10000

00000

11111

000010111101011101111010

10111

0000

00

0

];

Hope this helps you.

Regards,

jagan.

Comments
MVP
MVP

Hi Jagan,

QlikView is very kind here and lets us do it more easily. It's just about number formatting.

Load

           Binary,

           num(Num#(Binary, '(Bin)')) as Decimal

Inline [

Binary   

     1011  

     10000 

     00000 

     11111 

     1011110101

     10111 

     0000 

     00 

     0 

];

Untitled.png

MVP
MVP

Hi,

But there is an issue with Binary numbers  with greater than 14 digits, it is getting null.

=num(Num#('111111111111111', '(Bin)'))


Regards,

Jagan.

tresesco this post by jagan stem from following discussion: Converting binary sequence to decimal

MVP
MVP

Yes Sunny!!!!  This can deal with any number of Binary digits.

Regards,

jagan.

MVP
MVP

Yes, when it goes beyond 14 digits, number formatting fails. . Its a limitation by qv number system that supports only 64-bit IEEE, and

The 64-bit IEEE float can only show 14 digits

Version history
Revision #:
1 of 1
Last update:
‎01-14-2016 08:31 PM
Updated by: