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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Integer to Binary conversion 1

Status
Not open for further replies.

CMR

Programmer
Apr 30, 2002
76
AU
Hi all.
Is there any way I can convert an Integer to binary in CR 8.0? I'm using the field to store a bunch of flags and I must do a bit comparison to get at the individual flags. I can't find anything in the documentation and I'm beginning to think it's not possible. Can anyone prove me wrong? (I hope so!)

thanks
CMR

 
You could write a UFL to perform logical AND on the number without converting to binary. There may be another way of doing AND, I'm not sure.
Alternatively, this function returns a STRING representation of a binary number. It would need padding to however many bits you need.

stringvar bin := "";
numbervar num := {@YOUR NUMBERHERE};
while num>0 do (
bin := bin + totext(remainder(num,2),0);
num := int(num/2);

);
strreverse(bin)
Andrew Baines
Chase International
 
I am not aware of any built in function to do this. However, there is an algorithm that you could follow and you could code it yourself relatively quickly. Post your email address, or send it to me and I will be more than happy to send you the code. treusch@smithdata.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top