# Re: Binary manipulation

• To: jbk@world.std.com (Jeffrey B Kane)
• Subject: Re: Binary manipulation
• From: cartier@math.uqam.ca (Guillaume Cartier)
• Date: Mon, 23 Nov 92 16:41:10 -0500
• Cc: info-mcl@cambridge.apple.com (Macintosh Common Lisp)

```<---
| 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) *
*********************************************************************

```