[Gambas-user] Bit manipulation functions

Benoît Minisini gambas at ...1...
Mon Nov 22 21:41:02 CET 2010


> Great! it's easy!
> 
> Thanks very much!
> 
> On Sat, 2010-11-20 at 18:30 +0200, Jussi Lahtinen wrote:
> > because lsr processes 32 bits of the short -9 and not 64 bits of the
> > 
> > > long binary number?
> > 
> > Yes, -9 is considered as short.
> > Try:
> > ? bin(lsr(clng(-9),1), 64)
> > 0111111111111111111111111111111111111111111111111111111111111011
> > 
> > Jussi

Bit manipulation functions work on the number of bits defined by their 
argument: Byte -> 8, Short -> 16, Integer (the default for numeric values) -> 
32, Long -> 64.

So Lsr(-9, 1), which does not keep the sign of its argument, does that:

	11111111111111111111111111110111
->	01111111111111111111111111111011

But Bin$() always print 64 binary digits for negative numbers, so you think 
that it was wrong.

Regards,

-- 
Benoît Minisini




More information about the User mailing list