1. ver 4.0 and_bits question

-- test.exw  program using SVN 1539 on WIN98 
 
include std/math.e 
 
atom x 
 
x = 16777220 
? and_bits(x,#F) 
 
x = #1000004 
? and_bits(x,#F) 
 
x = -16777220 
? and_bits(x,#F) -- <-- why does this return a different result 
 
x = -#1000004 
? and_bits(x,#F) -- <-- why does this return a different result 
 
x = #81000004    -- <-- note high bit set 
? and_bits(x,#F) 
 
if getc(0) then 
-- pause 
end if 
 
-- end program 
new topic     » topic index » view message » categorize

2. Re: ver 4.0 and_bits question

Bernie,

FYI, this isn't a 4.0 issue. It has to do with how euphoria interprets hex numbers. This should help with some insights:

procedure examine( atom x ) 
	printf(1, "\nDecimal: %d\nHex:     %x\nx & 0xf: %x\n", {x,x, and_bits( x, #f)}) 
end procedure 
 
examine( 16777220 ) 
examine( #1000004 ) 
examine(-16777220 ) 
examine( -#1000004 ) 
examine( #81000004 ) 

This code produces:

Decimal: 16777220 
Hex:     1000004 
x & 0xf: 4 
 
Decimal: 16777220 
Hex:     1000004 
x & 0xf: 4 
 
Decimal: -16777220 
Hex:     FEFFFFFC 
x & 0xf: C 
 
Decimal: -16777220 
Hex:     FEFFFFFC 
x & 0xf: C 
 
Decimal: 2164260868 
Hex:     81000004 
x & 0xf: 4 
Matt

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

Search



Quick Links

User menu

Not signed in.

Misc Menu