Games:
Seafox
Pages:
Syntax Error Software
itch.io page
Online Chess
http://gameknot.com/#paul_nicholls
Still, you're swap32 function should be longword, not word, no?
word and $FFFF0000 === 0 -- ALWAYS
word shl 16 === 0 -- ALWAYS.
So in effect:
result:=(Swap16(x and $ffff) shl 16) or Swap16((x and $ffff0000) shr 16);
is the same thing as saying
result:=0;
Which means on big-endian systems when your swap function is called, you'll get nothing but zero.
Also, you're sending zero to your swap16 function...
Is what you should have there. What you have right now won't work... Thankfully it's only called on big endian systems -- and you've probably only tested little endian.Code:function Swap32(x:longword):longword; begin result:=(Swap16(x and $ffff) shl 16) or Swap16(x shr 16); end;
It may also need typecasting forced, since swap16 returns word, not longword meaning that shl 16 could STILL result in zero.
Last edited by deathshadow; 27-08-2011 at 08:28 PM.
The accessibility of a website from time to time must be refreshed with the blood of designers and owners. It is its natural manure
Sorry, you're wrong. See my code again:
The first swap16 call gets "x and $ffff", and the result of it will shifted 16 bits to left, which's correct.Code:function Swap32(x:word):word; begin result:=(Swap16(x and $ffff) shl 16) or Swap16((x and $ffff0000) shr 16); end;
The second swap16 call gets "(x and $ffff0000) shr 16" or short "x shr 16", and the result of it will not shifted because it was already shifted 16 bits to right, which's also correct.
I guess, you had simply overlook the correct nested levels of the (...) blocks in my code.
Last edited by BeRo; 31-08-2011 at 09:46 AM.
Forgot about this thread... but:
function Swap32(x:word):word;
word is 16 bit unsigned... can only contain 0..$FFFF -- therein:
x and $ffff returns X
x and $ffff0000 returns 0, always...
since $FFFF is the highest number WORD can contain, $0000FFFF and $FFFF0000 == 0, ALWAYS. X in your function CANNOT hold a value that would return anything but zero on that second AND.... EVER.
See what I'm saying? for that function to work X would have to be DWORD and/or Longint... 32 bit... not 16 bit which is what WORD is.
Last edited by deathshadow; 25-09-2011 at 12:05 PM.
The accessibility of a website from time to time must be refreshed with the blood of designers and owners. It is its natural manure
Bookmarks