RE: not_bits() not_working()

new topic     » topic index » view thread      » older message » newer message

Al Getz wrote:

> I've found that Euphorias not_bits() function doesnt really work
> correctly.
> 
> For example:
> 
> atom a,x
> a=2
> 
> x=not_bits(a)
> 
> --now x equals -3, which isnt correct.
> --x should be equal to the 8 digit hex equivalent of -3,
> --right?

Actually, it is. not_bits() works exactly as it says it does (although 
it does seem odd):

"Results are treated as signed numbers. They will be negative when the 
highest-order bit is 1." -- Refman

So the bits are correct.  The quickest way to convert to unsigned (if 
that's what you want) seems to be to have 4-bytes allocated and do a 
poke4/peek4u after not_bits.  (I just tested this vs adding 2^32 and vs 
using xor_bits against a constant equal to 2^32-1). (These were tested 
with Win2K, P3, 1.1GHz)

If you printf with %x (hex formatting) or use int_to_bits, you'll see 
that the bits are correct.

Matt Lewis

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu