Yashied Posted April 11, 2009 Share Posted April 11, 2009 expandcollapse popupfunc _GetBit($iValue, $iPos, $iCount = 1) if ($iPos < 0) or ($iCount <= 0) then return 0 endif local $iMask = 0 for $i = 1 to $iCount $iMask = BitShift($iMask, -1) + 1 next return BitAND(BitShift($iValue, $iPos), $iMask) endfunc; _GetBit func _SetBit($iValue, $iPos, $iBit, $iCount = 1) if ($iPos < 0) or ($iCount <= 0) then return $iValue endif local $iMask = 0 for $i = 1 to $iCount $iMask = BitShift($iMask, -1) + 1 next $iMask = BitShift($iMask, -$iPos) if $iBit = 0 then return BitAND($iValue, BitXOR($iMask, 0xFFFFFFFF)) else return BitOR($iValue, $iMask) endif endfunc; _SetBit func _InvBit($iValue, $iPos, $iCount = 1) if ($iPos < 0) or ($iCount <= 0) then return $iValue endif local $i for $i = 1 to $iCount $iValue = _SetBit($iValue, $iPos + ($i - 1), 1 - _GetBit($iValue, $iPos + ($i - 1))) next return $iValue endfunc; _InvBit func _BitToStr($iValue, $iPos = 0, $iCount = 32) if ($iPos < 0) or ($iCount <= 0) then return '' endif local $i, $t = '' for $i = 1 to $iCount $t = _GetBit($iValue, $iPos) & $t $iPos += 1 next return $t endfunc; _BitToStr func _StrToBit($sString) local $i, $b, $ret = 0, $n = StringLen($sString) for $i = 1 to $n $b = StringRight($sString, 1) if ($b <> '0') and ($b <> '1') then return '' endif $ret = _SetBit($ret, $i - 1, ($b = '1')) $sString = StringTrimRight($sString, 1) next return $ret endfunc; _StrToBitExamples_SetBit(0x0F, 5, 1, 2) ; 00001111b (0x0F) => 01101111b (0x6F)_GetBit(0x6F, 4, 4) ; 01101111b (0x6F) => 0110b (0x6)_InvBit(0x6F, 0, 4) ; 01101111b (0x6F) => 01100000 (0x60)_BitToStr(0x6F, 4, 4); 01101111b (0x6F) => "0110"_StrToBit("01101111") ; "01101111" => 0x6F My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
hunt Posted October 30, 2009 Share Posted October 30, 2009 Thank you very much! Link to comment Share on other sites More sharing options...
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