Forum > General

Shr function - pascal and php

<< < (2/4) > >>

marcov:
500-244=256

The typing of your intermediate result is wrong. A byte can only contain 0..255.

Marc:
((Seed shr a) and $000000FF) ->

1001 shr 1 -> 500

500 and $FF -> 244

I wonder why only the part with a is anded with $FF and not b and C

thats why I asked what values you do expect for:

  PKV_GetKeyByte(1001, 24, 3, 200)
  PKV_GetKeyByte(1001, 10, 0, 56)
  PKV_GetKeyByte(1001, 1, 2, 91)
  PKV_GetKeyByte(1001, 7, 1, 100)

dfeher:
Hi!

At first sight, I think the Pascal and PHP codes returns different results because of using non-bitwise operators in the PHP code:


--- Code: ---      if(  $a % 2 == 0 )
       {
          $result = ( ( $Seed >> $a ) && 0x000000FF ) xor ( ( $Seed >> $b ) || $c );
       }else
       {
          $result = ( ( $Seed >> $a ) && 0x000000FF ) xor ( ( $Seed >> $b ) && $c );
       }       

--- End code ---

&& is logical and, || is logical or.

I think you have to use & and | instead, and ^ instead of xor.

I hope this helps!

xinyiman:
1:  PKV_GetKeyByte(1001, 24, 3, 200)
2:  PKV_GetKeyByte(1001, 10, 0, 56)
3:  PKV_GetKeyByte(1001, 1, 2, 91)
4:  PKV_GetKeyByte(1001, 7, 1, 100)

Result php

1: 1001
2: 1017
3: 174
4: 99

Result pascal

1: 233
2: 249
3: 174
4: c

but I changed the code as said dfeher

Marc:
Good that you changed :)

Resultvalues of 1001 or 1017 will never fit in a byte.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version