Luigi Posted May 15, 2011 Share Posted May 15, 2011 (edited) My first script in the forum. This is a simple code to verify if a number is contained in binary number. expandcollapse popup#comments-start This script check if $Inside is contained in $Binary. 17 = 1 + 16 _CheckBin(17,15) = 0 _CheckBin(17,1) = 1 _CheckBin(17,3) = 0 _CheckBin(17,16) = 1 #comments-end #include <Array.au3> ConsoleWrite(_CheckBin(17,15)) Func _CheckBin($Binary,$Inside) Dim $BinTable[1] Local $BinOriginal, $BinTable If $Binary <0 or $Inside<0 Then Return 0 If $Inside > $Binary Then Return 0 $BinRest=1 $BinExp = 0 $BinarioString="" While $Binary >0.5 $BinRest = _Rest($Binary,2) $Binary = int($Binary/2) $BinString = $BinarioString & $BinRest ReDim $BinTable[$BinExp+1] IF $BinRest = 1 Then $BinOriginal = $BinOriginal + 2^($BinExp) $BinTable[$BinExp] = 2^($BinExp) Endif $BinExp = $BinExp + 1 WEnd _ArraySearch($BinTable, $Inside, 0, 0, 0, 0,0) If @error Then Return 0 Else Return 1 EndIf EndFunc ; _CheckBin() Func _Rest($Dividend,$Divider) Return (($Dividend / $Divider)-int(($Dividend / $Divider)))*2 EndFunc ; _Rest() CheckBin02.au3 Edited October 19, 2019 by Luigi Visit my repository Link to comment Share on other sites More sharing options...
Sapient Posted May 16, 2011 Share Posted May 16, 2011 (edited) "verify if a number is contained in binary number" ? I think you are attempting to describe the following bitwise operation: return (BitOR($whole, $part) = $whole) ; edited according to comment below ; replaced == with = comparison operator which could also be written: return NOT(BitXOR($whole, BitOR($whole, $part))) Edited May 16, 2011 by Sapient Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 16, 2011 Share Posted May 16, 2011 "verify if a number is contained in binary number" ? I think you are attempting to describe the following bitwise operation: return (BitOR($whole, $part) == $whole) Why are you doing a string comparison (see "Operators" in helpfile)? I think you meant: ConsoleWrite((BitOR(17, 15) = 17) & @CRLF) .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Sapient Posted May 16, 2011 Share Posted May 16, 2011 Why are you doing a string comparison (see "Operators" in helpfile)? I think you meant: ConsoleWrite((BitOR(17, 15) = 17) & @CRLF) I must be getting rusty if I had forgotten that. Thanks for reminding me, though. Link to comment Share on other sites More sharing options...
Luigi Posted May 19, 2011 Author Share Posted May 19, 2011 I hate me! grrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr I lost my time writing this thing... and they have a solution in 1 code line! I hate me! grrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr 8( Anyway... thanks (@Sapient and @AdmiralAlkex)for your reply, is very useful for me. Visit my repository Link to comment Share on other sites More sharing options...
Sapient Posted May 20, 2011 Share Posted May 20, 2011 I lost my time writing this thing... and they have a solution in 1 code line!True, but my solution only works for binary numbers that are up to 32 bits.If you want to compare larger binaries (e.g. graphics files) a special function could still be needed. Link to comment Share on other sites More sharing options...
jaberwacky Posted May 22, 2011 Share Posted May 22, 2011 I hate me! grrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrI lost my time writing this thing... and they have a solution in 1 code line!I hate me! grrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr8(Anyway... thanks (@Sapient and @AdmiralAlkex)for your reply, is very useful for me.Don't beat yourself up dude! Everybody has to start somewhere. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? 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