1. and_bits() behavior

Should this be right?

ADMIN_ONLY = 128
btype = -1

?and_bits(ADMIN_ONLY,btype)

It's returning 128!

new topic     » topic index » view message » categorize

2. Re: and_bits() behavior

c.k.lester wrote:

> Should this be right?
> 
> ADMIN_ONLY = 128
> btype = -1
> 
> ?and_bits(ADMIN_ONLY,btype)
> 
> It's returning 128!

That's OK.
Run the following code, and maybe then you can solve the riddle yourself. smile
include machine.e
? int_to_bits(-1, 8)

Regards,
   Juergen

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

3. Re: and_bits() behavior

c.k.lester wrote:
> 
> Should this be right?
> 
> ADMIN_ONLY = 128
> btype = -1
> 
> ?and_bits(ADMIN_ONLY,btype)
> 
> It's returning 128!

Hi c.k.
Run this...

integer i1
i1=-1
printf(1,"%x\n",i1)
printf(1,"%d\n",and_bits(i1,128))
while get_key()=-1 do end while


--Quark

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

4. Re: and_bits() behavior

Thanks, Juergen and Quark. :)

My only response is, "BoooOooOoOOOOOo."
So I gotta test for -1. waaaAAAAaahhhh.

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

5. Re: and_bits() behavior

Juergen Luethje wrote:
> 
> c.k.lester wrote:
> 
> > Should this be right?
> > 
> > ADMIN_ONLY = 128
> > btype = -1
> > 
> > ?and_bits(ADMIN_ONLY,btype)
> > 
> > It's returning 128!
> 
> That's OK.
> Run the following code, and maybe then you can solve the riddle yourself. smile
> }}}
<eucode>
> include machine.e
> ? int_to_bits(-1, 8)
> </eucode>
{{{

> Regards,
>    Juergen

BTW, I experimented with this today. The highest bit count that I could go to
and still get all ones was 53. At 54 and above, I got all zeroes.

--
"Any programming problem can be solved by adding a level of indirection."
--anonymous
"Any performance problem can be solved by removing a level of indirection."
--M. Haertel
"Premature optimization is the root of all evil in programming."
--C.A.R. Hoare
j.

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

6. Re: and_bits() behavior

Jason Gade wrote:
> 
> Juergen Luethje wrote:
> > 
> > That's OK.
> > Run the following code, and maybe then you can solve the riddle yourself.
> > smile
> > }}}
<eucode>
> > include machine.e
> > ? int_to_bits(-1, 8)
> > </eucode>
{{{


> 
> BTW, I experimented with this today. The highest bit count that I could go to
> and still get all ones was 53. At 54 and above, I got all zeroes.

I believe that you've hit the precision limit of a double, which is probably
the reason for this.

Matt

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

Search



Quick Links

User menu

Not signed in.

Misc Menu