cancel
Showing results for 
Search instead for 
Did you mean: 

Convert a integer to binary

Former Member
0 Kudos

I am trying to convert a number to a binary value. The application I am dealing with has checkbox questions and multiple answers can be checked. The values in the field vary depending on the number of answers available.

Thus if there are 4 checkbox answers the values can range from 1 to 15

checkbox one value = 1

checkbox two value = 2

checkbox three value = 4

checkbox four value = 8

so if all boxes are checked, the value would be 15 in the database.

binary value of 15 would be 1111

if only one and three are checked, the value is 5 which would be 101

This would allow me to figure out the boxes that were checked for reporting.

We have some questions with 10+ check boxes (medical application)

Any ideas would be greatly appreciated (of a function you have developed)

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

try this

local numbervar x;

local stringvar binary;

x := {your number to convert};

while x (not equal to symbols) 0 do

(binary:= totext(remainder(x,2),0) & binary;

x:= int(x/2));

binary

Former Member
0 Kudos

OK, I get the idea, but when I put this into my report to convert the answer,

I would like to have leading zero's so I can evaluate each question.

If I had 9 possible checkboxes and the value of all the answers is 4, the value of binary is 100

but I have 6 other checkboxes prior to this that should be 0 so I would like to see the number 4 be displayed as 000000100

Former Member
0 Kudos

If you have a maximum of 9 questions then add the following enclosed in * to your formula,

if you have more question you need to chnage the 9 value to the maximum number of questions

while x (not equal to symbols) 0 do

(binary:= totext(remainder(x,2),0) & binary;

x:= int(x/2));

********************************

binary:= replicatestring('0', 9 - length(binary));

********************************

binary

Former Member
0 Kudos

Thanks for the help - at least now we can write reports to summarize each answer as an individual report but CR does not handle the ability to summarize all the the possible answers on one question because you only get one detail record. This will work, but will just have to run 9 seperate reports to summarize each possible answer to a question. This will get us up to standards on our medical reporting requirements.

Mark Olson

Answers (0)