Hi,
Today I needed to convert a decimal value to binary in Crystal reports and ran into this thread on the net. As obvious I did not find a solution so based upon the information above I created my own custom function in Crystal. So in case still needed here is how to do it:
//Start of Function
Function (NumberVar NumberToConvert)
stringvar BinaryString;
While Int(NumberToConvert) > 0
Do
(
BinaryString := TOTEXT(Int(NumberToConvert) mod 2,0) + BinaryString;
NumberToConvert := Int(NumberToConvert) / 2;
);
BinaryString;
//End of Function
You can use to code above to make your own function in Crystal and then use the function in any way you can use function. Just provide a Decimal and you get the binary value returned in a text-string.
Of course you can extend the function with padding 0 etc. but for the basics this will do.
Currently the formula convert 9 into 1101, if you need the result to be 1011 you should change:
BinaryString := TOTEXT(Int(NumberToConvert) mod 2,0) + BinaryString;
into:
BinaryString := BinaryString + TOTEXT(Int(NumberToConvert) mod 2,0);
I have test this on Crystal v10.
Regards,
Henk