[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Binary manipulation



<---
| What is the best way to do binary manipulation of data within MCL?
| I need to do the equivalent of shifts, ands, nors, ors, etc., but the problem
| I'm having is doing these with integers and fixnums  How would you convert the following
| to mcl:
| 
| {
|         short var1 47;
|         unsigned long var2 0x322459;
| 
|         *((var1 & 0x7 << 3) + var2)
| }
| 
| going back and forth between MCL fixnum and bit-arrays (without losing data)?
| 
|         Jeffrey
--->

If I understand your problem correctly you don't need bit-arrays
and can use the whole bunch of CLtL2's boolean functions that will
manipulate integers. See sections 12.7 and 12.8 of CLtL2.

Examples:

? (logior 3 4 5)
7
? (lognot 45)
-46
? (logand 23 1 456)
0

Guillaume.

*********************************************************************
* Guillaume Cartier                 (514) 844-5294 (maison)         *
* L.A.C.I.M.                        (514) 987-4290 (bureau)         *
* Universite du Quebec a Montreal   (514) 987-8477 (telecopieur)    *
* Montreal, Quebec, Canada          cartier@math.uqam.ca (internet) *
*********************************************************************