How to implement Zero FillRight Shift (>>>)? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

How to implement Zero FillRight Shift (>>>)?

07 Jun 2019, 01:46

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)
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to implement Zero FillRight Shift (>>>)?  Topic is solved

07 Jun 2019, 03:00

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)
}
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Re: How to implement Zero FillRight Shift (>>>)?

07 Jun 2019, 06:28

Great! Just need to perform & operation with 0xFFFFFFFF, why ?

Code: Select all

msgbox % ( -9 & 0xFFFFFFFF ) >> 2
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to implement Zero FillRight Shift (>>>)?

07 Jun 2019, 09:46

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.
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Re: How to implement Zero FillRight Shift (>>>)?

07 Jun 2019, 11:12

Exactly. Thank you very much!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ArkuS, mikeyww and 326 guests