Groups | Search | Server Info | Login | Register


Groups > comp.lang.lisp > #60727

Re: the unsigned right shift operator in CL >>>

From Aidan Kehoe <kehoea@parhasard.net>
Newsgroups comp.lang.lisp
Subject Re: the unsigned right shift operator in CL >>>
Date 2025-10-16 19:04 +0100
Message-ID <87wm4uu3j6.fsf@parhasard.net> (permalink)
References <m3ms5s3atl.fsf@pison.robolove.meer.net>

Show all headers | View raw


 Ar an cúigiú lá déag de mí Deireadh Fómhair, scríobh Madhu: 

 > I was trying to wrap my head the >>> operator
 > 
 > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift
 > 
 > 	The unsigned right shift (>>>) operator returns a number whose
 > 	binary representation is the first operand shifted by the
 > 	specified number of bits to the right. Excess bits shifted off
 > 	to the right are discarded, and zero bits are shifted in from
 > 	the left. This operation is also called "zero-filling right
 > 	shift", because the sign bit becomes 0, so the resulting number
 > 	is always positive.
 > 
 > This is what I understood but it looks too complicated

Something like:

(defun fixed-width-ash (width value count)
  (ash (logand value (lognot (ash -1 width))) count))

Construct an integer of the desired width that is all 1s, logand it with VALUE,
then shift by COUNT. 

 > PS. Anyone know what happened to PJB, his online presence seems to have
 > been discontinues.

I hadn’t followed him, worth reading?

 > https://stackoverflow.com/questions/1691292/how-to-do-bit-wise-zero-filling-right-shift-in-scheme
 > https://stackoverflow.com/questions/26151644/why-is-there-no-unsigned-left-shift-operator-in-java

-- 
‘As I sat looking up at the Guinness ad, I could never figure out /
How your man stayed up on the surfboard after fourteen pints of stout’
(C. Moore)

Back to comp.lang.lisp | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

the unsigned right shift operator in CL >>> Madhu <enometh@meer.net> - 2025-10-15 12:34 +0530
  Re: the unsigned right shift operator in CL >>> Aidan Kehoe <kehoea@parhasard.net> - 2025-10-16 19:04 +0100
    Re: the unsigned right shift operator in CL >>> Alan Bawden <alan@csail.mit.edu> - 2025-10-16 16:06 -0400
      Re: the unsigned right shift operator in CL >>> Aidan Kehoe <kehoea@parhasard.net> - 2025-10-16 21:55 +0100
        Re: the unsigned right shift operator in CL >>> Madhu <enometh@meer.net> - 2025-10-23 16:34 +0530
          Re: the unsigned right shift operator in CL >>> Alan Bawden <alan@csail.mit.edu> - 2025-10-24 02:29 -0400
            Re: the unsigned right shift operator in CL >>> Madhu <enometh@meer.net> - 2025-10-25 21:00 +0530
            Re: the unsigned right shift operator in CL >>> Kaz Kylheku <046-301-5902@kylheku.com> - 2026-03-12 18:00 +0000
              Re: the unsigned right shift operator in CL >>> Stefan Monnier <monnier@iro.umontreal.ca> - 2026-03-12 16:34 -0400
                Re: the unsigned right shift operator in CL >>> Kaz Kylheku <046-301-5902@kylheku.com> - 2026-03-16 20:14 +0000
  Re: the unsigned right shift operator in CL >>> Madhu <enometh@meer.net> - 2025-10-23 16:38 +0530

csiph-web