1. not_bits() not_working()

Hello,

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?

Take care for now,
Al

new topic     » topic index » view message » categorize

2. Re: not_bits() not_working()

Al Getz wrote:

> 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?

The *_bits() functions all return negative if the high bit of the result 
is 1. They use signed 32-bit ints internally I presume.

try:

function not_bitsU(atom a) -- U = Unsigned
     return #FFFFFFFF - a
end function

or better (but slower):

constant B32m1 = power(2,32)-1
function not_bitsU(atom a) -- U = Unsigned
     return B32m1 - and_bits(a, B32m1)
end function

Carl

-- 
[ Carl R White == aka () = The Domain of Cyrek = ]
[ Cyrek the Illogical /\ www.cyreksoft.yorks.com ]

new topic     » goto parent     » topic index » view message » categorize

3. Re: not_bits() not_working()

Al Getz wrote:
 
> atom a,x
> a=2
>
> x=not_bits(a)
>
> --now x equals -3, which isnt correct.


It is correct! look at this (or try it yourself):
---------------------------------------------------
printf(1,"%08x\n", 2 )			-- 00000002
printf(1,"%08x\n", not_bits(2) )	-- FFFFFFFD
---------------------------------------------------

Please notice also:

0000 0000 0000 0000 0000 0000 0000 0010 =  2 = #00000002
1111 1111 1111 1111 1111 1111 1111 1101 = -3 = #FFFFFFFD

Have a nice day, Rolf

new topic     » goto parent     » topic index » view message » categorize

4. Re: not_bits() not_working()

----- Original Message -----
From: "Al Getz" <Xaxo at aol.com>
To: "EUforum" <EUforum at topica.com>
Subject: not_bits() not_working()


>
>
> Hello,
>
> 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?
>

Sorry Al, but it does exactly what I'd expect it to do. Each bit in the
32-bit value is reversed. If it didn't work this way a number of functions
in win32lib would fail.

--
Derek

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu