Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
dana
Creator III
Creator III

Binary numbers display issues

Hi People,

I have a loop that generates binary numbers:

FOR i = 1 to 15
       LOAD

       text(num($(i), '(bin)'))   as Bin,
       RowNo()             as Row
       AutoGenerate(1);

NEXT i

 

The resulting table:

Decimal

Binary

1

1

2

10

3

11

4

100

5

101

6

110

7

111

8

1000

9

1001

10

1010

11

1011

12

1100

13

1101

14

1110

15

1111

 

There are a couple of issues I need to resolve:

  • Leading/ending zeros are not displayed for values.

           For example, 1 should be displayed as 1000 and not 1.

  • Some of the values are flipped.
    For example, 8 should be 0001 and not 1000.

   Since I plan the solution to work for N binary values, I need it to be generic.

Would appreciate some guidelines..

Thanks in advance!

 

 

 

Labels (1)
1 Solution

Accepted Solutions
marcus_sommer

The binary-logic starts from the right-side, not like normal numbers from left. It's not very clear what do you want to do but I could imagine the following posting may be useful for your task:

Anyone-familiar-with-importing-a-binary-field 

- Marcus

View solution in original post

4 Replies
marcus_sommer

The binary-logic starts from the right-side, not like normal numbers from left. It's not very clear what do you want to do but I could imagine the following posting may be useful for your task:

Anyone-familiar-with-importing-a-binary-field 

- Marcus

dana
Creator III
Creator III
Author

Hi Marcus,

I have written a script to generate dynamic generic keys for data reduction based on binary numbers. A value of 1 represents 'All'.

Therefore, it's important for me that the pattern would be correct.  Currently, I read the binary values from Excel, but I would like to generate them myself.  At the end, it will be a subroutine that will receive key fields and will generate the binary numbers according to a designated  key length.

I will check the post you've mentioned.

Thanks!

dana
Creator III
Creator III
Author

Hi Marcus,

The following script from your answer to the post does the job for me: 

t0:
//load *, V<<8 as X, V<<16 as Y, V<<24 as Z;
load *, repeat('0', 8 - len(text(num(V, '(bin)')))) & text(num(V, '(bin)')) as B;
load recno() -1 as V autogenerate 8;

V

B

0

00000000

1

00000001

2

00000010

3

00000011

4

00000100

5

00000101

6

00000110

7

00000111

 

I will define the autogenerate number as parameter.

Thanks for clarifying about the need to read from right to left!

Thanks for your help!

 

dana
Creator III
Creator III
Author

Hi Marcus,

Attached is my solution for generating generic keys based on binary numbers.

It includes your code as well.

Would appreciate your comments.

Thanks again for your help!