Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert integer into binary in crystal reports

Status
Not open for further replies.

priyanthan

Programmer
Jul 27, 2008
70
CA
Can anyone please help me how to convert a smallint value into a binary.


Thanks in advance.
 
I doubt that Crystal has such a function. POssibly you could do it in SQL via SQL Expression.

It always helps to give your Crystal version - 8, 8.5, 9, 10, 11 or whatever. Methods sometimes change between versions, and higher versions have extra options.


[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 11.5 with SQL and Windows XP [yinyang]
 



Hi,

Here's a simple function in VB...
Code:
Function Int2Bin(i As Integer) As String
    Dim n As Integer
    n = i
    Do
        Int2Bin = n Mod 2 & Int2Bin
        n = n \ 2
    Loop Until n = 0
End Function

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks for the reply.

Is crystal 8.5 supports logical 'AND'.

Thanks,
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top