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

LongInt To Bianary and V.V. conversion

Status
Not open for further replies.

TheElusiveYak

Programmer
Feb 8, 2004
19
US
Hello Again,
I'm working on a file encryption program which utilizes Wolfram's Cellular Automina in order to generate seemingly random alterations in the encoding... well anyhow I want to have the user enter a Longint key and convert it to a 16 cell boolean array. I've tried to figure out how to do it but im stumped. Also how would you convert it back? Any help with this would be appreciated!
 
I'm not sure exactly what you're looking to do. The problem though is solved by using your boolean operators.
AND will test for bits and XOR will toggle them. Couple them with IF tests and you can set your boolean array.

The only catch with doing this is that you're not going to be able to really relate a complete longint to 16 booleans in this way. A longint is 32 bits and a boolean is one bit (true or false). So you're going to have to lose some data somewhere or find another scheme (bytes maybe with a value of 0, 1, or 2?)
 
it's not that hard:
Loop 32 times:
if (longint mod 2) = 1 then boolean[n] is true, else false
longint := longint div 2 (or if you prefer, shr 1)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top