From: Andrei Stebakov
Subject: Bitwise operation in Lisp (CLisp)
Date: 
Message-ID: <2e04fd43.0503141443.2d54150f@posting.google.com>
Hi,

I am new to lisp and started playing with CLisp.
Could anyone give me hint where can I look to find the bitwise
operators (like ~, << , >> , & , ^, and | in C/C++).
I found some operators in GNU Emacs manual but guess they won't work
with my CLisp.

Thanks!
Andrei

From: jayessay
Subject: Re: Bitwise operation in Lisp (CLisp)
Date: 
Message-ID: <m3sm2xvnq0.fsf@rigel.goldenthreadtech.com>
·········@yahoo.com (Andrei Stebakov) writes:

> Hi,
> 
> I am new to lisp and started playing with CLisp.
> Could anyone give me hint where can I look to find the bitwise
> operators (like ~, << , >> , & , ^, and | in C/C++).
> I found some operators in GNU Emacs manual but guess they won't work
> with my CLisp.

I think you are probably looking for this:

http://www.lispworks.com/documentation/HyperSpec/Body/f_logand.htm
http://www.lispworks.com/documentation/HyperSpec/Body/f_logbtp.htm

and other friends in the same dictionary.


/Jon

-- 
'j' - a n t h o n y at romeo/charley/november com
From: Pascal Bourguignon
Subject: Re: Bitwise operation in Lisp (CLisp)
Date: 
Message-ID: <87psy1hiu7.fsf@thalassa.informatimago.com>
jayessay <······@foo.com> writes:

> ·········@yahoo.com (Andrei Stebakov) writes:
> 
> > Hi,
> > 
> > I am new to lisp and started playing with CLisp.
> > Could anyone give me hint where can I look to find the bitwise
> > operators (like ~, << , >> , & , ^, and | in C/C++).
> > I found some operators in GNU Emacs manual but guess they won't work
> > with my CLisp.
> 
> I think you are probably looking for this:
> 
> http://www.lispworks.com/documentation/HyperSpec/Body/f_logand.htm
> http://www.lispworks.com/documentation/HyperSpec/Body/f_logbtp.htm
> 
> and other friends in the same dictionary.

Note that instead of working with numbers, you can use actual bit
vectors (or even multidimensional bit arrays) and use the functions in
the bit- serie:  bit-and, bit-ior, etc.

    (bit-and #*1010 #*1100) --> #*1000
    (bit-ior #*1010 #*1100) --> #*1110
    (bit-not #*10)          --> #*01

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
In deep sleep hear sound,
Cat vomit hairball somewhere.
Will find in morning.
From: Petter Gustad
Subject: Re: Bitwise operation in Lisp (CLisp)
Date: 
Message-ID: <87mzt5jq1r.fsf@filestore.home.gustad.com>
jayessay <······@foo.com> writes:

> ·········@yahoo.com (Andrei Stebakov) writes:
>
>> Hi,
>> 
>> I am new to lisp and started playing with CLisp.
>> Could anyone give me hint where can I look to find the bitwise
>> operators (like ~, << , >> , & , ^, and | in C/C++).
>> I found some operators in GNU Emacs manual but guess they won't work
>> with my CLisp.
>
> I think you are probably looking for this:
>
> http://www.lispworks.com/documentation/HyperSpec/Body/f_logand.htm
> http://www.lispworks.com/documentation/HyperSpec/Body/f_logbtp.htm

And possibly this:

http://www.lispworks.com/documentation/HyperSpec/Body/f_ldb.htm

In langueages like C etc. you do shifts and masks to extract bits. In
Common Lisp you can extract using LDB. To extract bits 5,6,7,8
(lsb being 0) you would do

C:   ((word >> 5) & 0xf)
CL:  (ldb (byte 4 5) word)  ; extract 4 bits starting at bit 5

You can also set the specified bits to a value

 (let ((word #xfeef))
   (format t "bits are ~X~%" (ldb (byte 4 5) word))
   (setf (ldb (byte 4 5) word) #x8)
   (format t "word is ~X~%" word)
   word)
bits are 7
word is FF0F
65295

Or use dpb
http://www.lispworks.com/documentation/HyperSpec/Body/f_dpb.htm#dpb

Petter 
-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?