RE: not_bits() not_working()

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

Matt Lewis wrote:
> 
> 
> 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
> 

Hello Matt,

I have been using poke4 and peek4u to convert because it seems
to be the most reliable way to do it with only three ops, however
now ill have to check out Carls idea too.  There is a chance that
my argument will always be positive.

I just cant help wondering why not_bits() doesnt work the way
the other _bits functions work, or did i miss something?
Is there any real use for getting a return value of -3 for
not_bits(2) out there? anyone?

Take care,
Al

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

Search



Quick Links

User menu

Not signed in.

Misc Menu