in reply to Why are hex numbers inside strings extrapolating to numbers (incorrectly)?
And first glance, it would seem some sort of floating point conversion is going on, but exactly what, I don't know except that 9/8 = 1.125 (but why eight?) Actually, the following pattern exists:print "0x1" + 0 = 1 print "0x2" + 0 = 1 print "0x3" + 0 = 1.5 print "0x4" + 0 = 1 print "0x5" + 0 = 1.25 print "0x6" + 0 = 1.5 print "0x7" + 0 = 1.75 print "0x8" + 0 = 1 print "0x9" + 0 = 1.125 print "0x10" + 0 = 1
0x01 is probably being interpreted as just a "0x1", whatever that is. Since all the results are on powers of 2 boundaries, I would presume some bit-oriented operation is happening.print "0x1" + 0 = 1 1/1 = 1 print "0x2" + 0 = 1 2/1 = 2 print "0x3" + 0 = 1.5 3/1.5 = 4 print "0x4" + 0 = 1 4/1 = 4 print "0x5" + 0 = 1.25 5/1.25 = 4 print "0x6" + 0 = 1.5 6/1.5 = 4 print "0x7" + 0 = 1.75 7/1.75 = 4 print "0x8" + 0 = 1 8/1 = 8 print "0x9" + 0 = 1.125 9/1.125 = 8 print "0x10" + 0 = 1 10/1 = 10
Good question!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Why are hex numbers inside strings extrapolating to numbers (incorrectly)?
by MrNobo1024 (Hermit) on Feb 26, 2001 at 21:02 UTC | |
by mr.nick (Chaplain) on Feb 26, 2001 at 21:06 UTC |