Hello,
How to implement JS Zero FillRight Shift (>>>) with AHK?
JavaScript (Zero Fill) Right Shift (>>>)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#%3E%3E%3E_(Zero-fill_right_shift)
How to implement Zero FillRight Shift (>>>)? Topic is solved
Re: How to implement Zero FillRight Shift (>>>)? Topic is solved
Code: Select all
#NoEnv
ToShift := 9
MsgBox, 0, ZeroFillRightShift32, % ToShift . " >> 2 = " . ZeroFillRightShift32(ToShift, 2)
ToShift := -9
MsgBox, 0, ZeroFillRightShift32, % ToShift . " >> 2 = " . ZeroFillRightShift32(ToShift, 2)
ExitApp
ZeroFillRightShift32(Num, Shift) {
Return ((Num & 0xFFFFFFFF) >> Shift)
}
Re: How to implement Zero FillRight Shift (>>>)?
Great! Just need to perform & operation with 0xFFFFFFFF, why ?
Code: Select all
msgbox % ( -9 & 0xFFFFFFFF ) >> 2
Re: How to implement Zero FillRight Shift (>>>)?
AHK stores all integer values as 64-bit signed integers (Int64). All negative integers have bit 63 (bits are counted from 0 to 63) set to 1 (0x8000000000000000). When shifted to the right, AHK restores this sign bit after each bit shift.
Var & 0xFFFFFFFF clears the contents of the bits 32 - 63, i.e. sets the sign bit to 0. That's why righ-shifting refills the sign bit with 0 after shifting.
Var & 0xFFFFFFFF clears the contents of the bits 32 - 63, i.e. sets the sign bit to 0. That's why righ-shifting refills the sign bit with 0 after shifting.
Re: How to implement Zero FillRight Shift (>>>)?
Exactly. Thank you very much!