Created
November 27, 2014 07:24
-
-
Save jNizM/16a68ff558222253add9 to your computer and use it in GitHub Desktop.
[AHK] BitCalc (Visual Bitwise Operations)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; GLOBAL SETTINGS =============================================================================================================== | |
;#Warn | |
#NoEnv | |
#SingleInstance Force | |
global WS_VSCROLL := 0x00200000 | |
; GUI =========================================================================================================================== | |
Gui, Margin, 5, 5 | |
Gui, Font, s10, Consolas | |
Gui, Add, Edit, xm ym w140 h22 0x0002 gBitCalc vBCv1, 0x0800 | |
Gui, Add, DropDownList, x+20 yp w120 AltSubmit gBitCalc vBC, BitAnd||BitOr|BitXor|BitShift Left|BitShift Right | |
Gui, Add, Edit, x+20 ym w140 h22 0x0002 gBitCalc vBCv2, 0x0202 | |
Gui, Font, s9, Consolas | |
Gui, Add, Edit, xm y+5 w240 r6 -0x200000 0x0880 gBitCalc vBCRB | |
Gui, Add, Edit, x+0 yp w100 r6 -0x200000 0x0880 gBitCalc vBCRH | |
Gui, Add, Edit, x+0 yp w100 r6 -0x200000 0x0880 gBitCalc vBCRD | |
Gui, Show, AutoSize | |
BitCalc: | |
Gui, Submit, NoHide | |
if (BC = 1) | |
{ | |
OutPutB := ConvertToBin(BCv1) "`n&`n" ConvertToBin(BCv2) "`n=`n" ConvertToBin(BCv1 & BCv2) | |
OutPutH := FormatIntH(BCv1) "`n&`n" FormatIntH(BCv2) "`n=`n" FormatIntH(BCv1 & BCv2) | |
OutPutD := FormatHexD(BCv1) "`n&`n" FormatHexD(BCv2) "`n=`n" FormatHexD(BCv1 & BCv2) | |
GuiControl,, BCRB, % OutPutB | |
GuiControl,, BCRH, % OutPutH | |
GuiControl,, BCRD, % OutPutD | |
} | |
else if (BC = 2) | |
{ | |
OutPutB := ConvertToBin(BCv1) "`n|`n" ConvertToBin(BCv2) "`n=`n" ConvertToBin(BCv1 | BCv2) | |
OutPutH := FormatIntH(BCv1) "`n|`n" FormatIntH(BCv2) "`n=`n" FormatIntH(BCv1 | BCv2) | |
OutPutD := FormatHexD(BCv1) "`n|`n" FormatHexD(BCv2) "`n=`n" FormatHexD(BCv1 | BCv2) | |
GuiControl,, BCRB, % OutPutB | |
GuiControl,, BCRH, % OutPutH | |
GuiControl,, BCRD, % OutPutD | |
} | |
else if (BC = 3) | |
{ | |
OutPutB := ConvertToBin(BCv1) "`n^`n" ConvertToBin(BCv2) "`n=`n" ConvertToBin(BCv1 ^ BCv2) | |
OutPutH := FormatIntH(BCv1) "`n^`n" FormatIntH(BCv2) "`n=`n" FormatIntH(BCv1 ^ BCv2) | |
OutPutD := FormatHexD(BCv1) "`n^`n" FormatHexD(BCv2) "`n=`n" FormatHexD(BCv1 ^ BCv2) | |
GuiControl,, BCRB, % OutPutB | |
GuiControl,, BCRH, % OutPutH | |
GuiControl,, BCRD, % OutPutD | |
} | |
else if (BC = 4) | |
{ | |
OutPutB := ConvertToBin(BCv1) "`n<<`n" ConvertToBin(BCv2) "`n=`n" ConvertToBin(BCv1 << BCv2) | |
OutPutH := FormatIntH(BCv1) "`n<<`n" FormatIntH(BCv2) "`n=`n" FormatIntH(BCv1 << BCv2) | |
OutPutD := FormatHexD(BCv1) "`n<<`n" FormatHexD(BCv2) "`n=`n" FormatHexD(BCv1 << BCv2) | |
GuiControl,, BCRB, % OutPutB | |
GuiControl,, BCRH, % OutPutH | |
GuiControl,, BCRD, % OutPutD | |
} | |
else if (BC = 5) | |
{ | |
OutPutB := ConvertToBin(BCv1) "`n>>`n" ConvertToBin(BCv2) "`n=`n" ConvertToBin(BCv1 >> BCv2) | |
OutPutH := FormatIntH(BCv1) "`n>>`n" FormatIntH(BCv2) "`n=`n" FormatIntH(BCv1 >> BCv2) | |
OutPutD := FormatHexD(BCv1) "`n>>`n" FormatHexD(BCv2) "`n=`n" FormatHexD(BCv1 >> BCv2) | |
GuiControl,, BCRB, % OutPutB | |
GuiControl,, BCRH, % OutPutH | |
GuiControl,, BCRD, % OutPutD | |
} | |
else | |
GuiControl,, BCRB, % "ERROR" | |
return | |
; FUNCTIONS ===================================================================================================================== | |
FormatIntH(Int) ; just me | |
{ | |
; Returns the hexadecimal string represention of the given integer value. | |
; Int - Integer value in the range of -9223372036854775808 to 9223372036854775807 | |
; Typ - Type to determine the size of the returned hex string. | |
; You may pass one of the keys in the 'Types' object. If the parameter is omitted or 'Auto' | |
; is passed explicitely, the size will be determined as 'Int64', 'Int', 'Short', or 'Char' | |
; according to the value of 'Int'. | |
if Int Is Not Integer | |
return "" | |
if (Int <= 255) && (Int >= -128) | |
Len := 2 | |
else if (Int <= 65535) && (Int >= -32768) | |
Len := 4 | |
else if (Int <= 4294967295) && (Int >= -2147483648) | |
Len := 8 | |
else | |
Len := 16 | |
VarSetCapacity(Hex, 17 << !!A_IsUnicode, 0) | |
if (DllCall("Shlwapi.dll\wnsprintf", "Str", Hex, "Int", 17, "Str", "%016I64X", "UInt64", Int, "Int") = 16) | |
return "0x" SubStr(Hex, StrLen(Hex) - Len + 1) | |
return "" | |
} | |
FormatHexD(nptr) | |
{ | |
static u := A_IsUnicode ? "_wcstoui64" : "_strtoui64" | |
static v := A_IsUnicode ? "_i64tow" : "_i64toa" | |
if (InStr(nptr, "0x")) | |
{ | |
VarSetCapacity(s, 66, 0) | |
value := DllCall("msvcrt.dll\" u, "Str", nptr, "UInt", 0, "UInt", 16, "CDECL Int64") | |
DllCall("msvcrt.dll\" v, "Int64", value, "Str", s, "UInt", 10, "CDECL") | |
return s | |
} | |
return nptr | |
} | |
ConvertToBin(h) | |
{ | |
loop 32 | |
b := h & 1 b, h := h >> 1 | |
return b | |
} | |
; EXIT ========================================================================================================================== | |
GuiEscape: | |
GuiClose: | |
ExitApp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment