FireFox Posted February 19, 2013 Posted February 19, 2013 (edited) Hi,I'm wondering how to make a zero-fill right shift in autoit as far as the BitShift function has no parameter for this.Here is an example in javascript : https://developer.mozilla.org/en-US/docs/Javascript/Reference/Operators/Bitwise_Operators#>>>_(Zero-fill_right_shift)Thanks for anyhelp,Br, FireFox. Edited February 20, 2013 by FireFox
czardas Posted February 19, 2013 Posted February 19, 2013 (edited) Perhaps something like this: For $i = 0 To 32 ConsoleWrite(LogicalBitShift(0x80000000 ,$i) & @LF) Next Func LogicalBitShift($dVal, $iShift) If $iShift > 0 And BitAND($dVal, 0x80000000) = 0x80000000 Then $dVal = BitShift($dVal, 1) $dVal = BitXor($dVal, 0x80000000) $iShift -= 1 EndIf Return BitShift($dVal, $iShift) EndFunc Edited February 19, 2013 by czardas FireFox 1 operator64 ArrayWorkshop
FireFox Posted February 20, 2013 Author Posted February 20, 2013 ohhhhhhhhh yeah ! Thanks again czardas 1
czardas Posted February 20, 2013 Posted February 20, 2013 No problem. You might want to add some error checks for the input parameters, I also think the function should be renamed to BitLogicalShift(). operator64 ArrayWorkshop
guinness Posted February 20, 2013 Posted February 20, 2013 Nice snippet czardas czardas 1 UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
UEZ Posted February 20, 2013 Posted February 20, 2013 (edited) This is a equivalent to the LogicalBitShift() function: For $i = 0 To 32 ConsoleWrite(Int(-1 * 0x80000000 / (2^$i)) & @LF) Next Br, UEZ Edited February 20, 2013 by UEZ FireFox 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
czardas Posted February 20, 2013 Posted February 20, 2013 (edited) This is a equivalent to the LogicalBitShift() function: For $i = 0 To 32 Ceiling(-1 * 0x80000000 / (2^$i)) Next Br, UEZ I'm getting totally different results: Local $dVar = 0xFFFFFFFF For $i = 0 To 32 ConsoleWrite(BitLogicalShift($dVar ,$i) & @LF) ConsoleWrite(Ceiling(-1 * $dVar / (2^$i)) & @LF) Next Func BitLogicalShift($dVal, $iShift) If $iShift > 0 And BitAND($dVal, 0x80000000) = 0x80000000 Then $dVal = BitShift($dVal, 1) $dVal = BitXor($dVal, 0x80000000) $iShift -= 1 EndIf Return BitShift($dVal, $iShift) EndFunc BTW, I changed the function name to a better one, but there is a problem. I'm trying to figure it out. Edited February 20, 2013 by czardas operator64 ArrayWorkshop
UEZ Posted February 20, 2013 Posted February 20, 2013 (edited) Well, calculating this way is limited to 0x80000000. Local $dVar = 0x80000000 For $i = 0 To 32 ConsoleWrite(BitLogicalShift($dVar, $i) & " / " & Equivalent($dVar, $i) & @LF) Next Func Equivalent($dVar, $i) If Hex($dVar) > Hex(0x80000000) Then Return SetError(0, 0, -1) Local $j = 1 If Hex($dVar) = Hex(0x80000000) Then $j *= -1 Return Int($j * $dVar / (2^$i)) EndFunc Func BitLogicalShift($dVal, $iShift) If $iShift > 0 And BitAND($dVal, 0x80000000) = 0x80000000 Then $dVal = BitShift($dVal, 1) $dVal = BitXor($dVal, 0x80000000) $iShift -= 1 EndIf Return BitShift($dVal, $iShift) EndFunc Br, UEZ Edited February 20, 2013 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
czardas Posted February 20, 2013 Posted February 20, 2013 (edited) Well, it has to work on any 32 bit integer. I have just realized that my method is faulty, because it isn't a true logical shift. The results of the first example fooled me into thinking it was working. It's actually completely broken.EditI think I know a way to fix it. Edited February 20, 2013 by czardas operator64 ArrayWorkshop
czardas Posted February 21, 2013 Posted February 21, 2013 (edited) I was thinking way too deep about this, The solution is very simple indeed. I have added error checks to force strict input parameters, rather unlike the arithmetic bitwise functions which don't seem to balk at anything. Local $dVar = 0x00010000 For $i = 21 To -20 Step -1 ConsoleWrite(BitLogicalShift($dVar ,$i) & @LF) Next Func BitLogicalShift($dVal, $iShift) If Not IsInt($dVal) Or Not IsInt($iShift) Then Return SetError(1, 0, "") If $iShift > 31 Or $iShift < -31 Then $dVal = 0 ; Out of range shift values always return zero. ElseIf $iShift > 0 And BitAND($dVal, 0x80000000) = 0x80000000 Then $dVal = BitXor(BitShift($dVal, 1), 0x80000000) $iShift -= 1 EndIf Return BitShift($dVal, $iShift) EndFunc Now the bit sequence can be shifted out of range in either direction. With the earlier version, the binary was looping back on itself with shift values greater than 31. That was not the intention. Edited February 21, 2013 by czardas FireFox 1 operator64 ArrayWorkshop
FireFox Posted February 21, 2013 Author Posted February 21, 2013 Thank you, it's fine for my needs czardas 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now