PhoenixXL Posted June 11, 2012 Share Posted June 11, 2012 Here is a code by UEZfor conversion of Integer to Binary and vice-versa from PostCode:#include <String.au3> Func Integer2Binary($in) ;coded by UEZ If $in = 0 Then Return 0 Local $bin While $in > 0 $bin &= Mod($in, 2) $in = Floor($in / 2) WEnd Return(_StringReverse($bin)) EndFunc Func Binary2Integer($in) ;coded by UEZ Local $int, $x, $i = 1, $aTmp = StringSplit(_StringReverse($in), "") For $x = 1 To UBound($aTmp) - 1 $int += $aTmp[$x] * $i $i *= 2 Next $aTmp = 0 Return StringFormat('%.0f', $int) EndFuncI wanted that is it possible to convert a float to binary for example what would be the Binary Version (0's and 1's) of 8.2Thnx for any helpRegardsPhoenix XL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 11, 2012 Moderators Share Posted June 11, 2012 PhoenixXL,Take a look here. And good luck as this is a fiendishly complicated area and the cause of many a grey hair! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
PhoenixXL Posted June 11, 2012 Author Share Posted June 11, 2012 (edited) M23, this is a fiendishly complicated area and the cause of many a grey hair!Nope I don't think so Thnx for the link i got the results for anyoneelse who has the similar problem herez the code Func _StrBinary($sString) Local $Binary = "" For $I = 1 To StringLen($sString) $Binary &= _IntBinary(Asc(StringMid($sString, $I, 1))) Next Return $Binary EndFunc Func _IntBinary($sInteger) If $sInteger <= 0 Then Return SetError(1,$sInteger,-1) Local $sParameter While $sInteger> 0 $sParameter &= Mod($sInteger, 2) $sInteger = _Quotient($sInteger, 2) WEnd $sParameter = _StringOpposite($sParameter) Return StringFormat("%08s", $sParameter) EndFunc Just use the Func _StrBinary() to convert a float type we can treat it as a string Regards Phoenix XL Edited June 11, 2012 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
trancexx Posted June 11, 2012 Share Posted June 11, 2012 It's rather complex only because our bitwise operations are still mostly limited to 32 bits. Other than that it's straightforward thing:Func _DoubleToBin($fValue) $fValue = Dec(Hex(Number($fValue, 3))) Local $bTemp = BinaryMid($fValue, 5, 4) Local $sOut For $i = 31 To 0 Step -1 $sOut &= BitAND(BitShift($bTemp, $i), 1) Next $bTemp = BinaryMid($fValue, 1, 4) For $i = 31 To 0 Step -1 $sOut &= BitAND(BitShift($bTemp, $i), 1) Next Return $sOut EndFunc Few more variations can be written. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 11, 2012 Moderators Share Posted June 11, 2012 PhoenixXL, Nope I don't think soWait until you try to do calculations with them - I bet you change your tune then. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Shaggi Posted June 11, 2012 Share Posted June 11, 2012 (edited) As said, this is quote hard because you can't directly work with such numbers in autoit. This would be my contribution: ConsoleWrite(DoubleToBinaryString(8.2)) Func DoubleToBinaryString($dIN) $sRet = "" $sHex = StringSplit(VariableToHexS($dIN),"") For $i = 1 to 16 $sRet &= HexCToBinary("0x" & $sHex[$i]) ;0x needed to correctly get autoit working with hex Next Return $sRet EndFunc Func VariableToHexS($dIn) Return Hex($dIn,16) EndFunc Func HexCToBinary($hIn) $sStr = "" For $i = 3 to 0 step -1 $sStr &= BitAnd(BitShift($hIn,$i),1) Next Return $sStr EndFunc This method can convert any hexstring to binary, so you could use it for strings and any number. Edited June 11, 2012 by Shaggi Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
PhoenixXL Posted June 11, 2012 Author Share Posted June 11, 2012 (edited) M23,I bet you change your tune then.Sorry if the tune got a bit over Take a look here.Upon taking the look at the previous link posted by M23i got 8.2=01000001000000110011001100110011with my Func _StrBinary i too got 8.2=0100000100000110011001100110011but but buttrancexx with your Func _DoubleToBin I got 8.2 = 0100000000100000011001100110011001100110011001100110011001100110and Shaggi with your Func DoubleToBinaryString too i got 8.2= 0100000000100000011001100110011001100110011001100110011001100110Maybe the link given by M23 is giving wrong results so as my FuncM23,I guess greying of hairs has already started Edited June 11, 2012 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
PhoenixXL Posted June 11, 2012 Author Share Posted June 11, 2012 Herez the code i used:expandcollapse popup#include <String.au3> #include <C:UsersabhishekDesktopPresentationAbhishekSCriptsMathsEx.au3> Func _DoubleToBin($fValue) $fValue = Dec(Hex(Number($fValue, 3))) Local $bTemp = BinaryMid($fValue, 5, 4) Local $sOut For $i = 31 To 0 Step -1 $sOut &= BitAND(BitShift($bTemp, $i), 1) Next $bTemp = BinaryMid($fValue, 1, 4) For $i = 31 To 0 Step -1 $sOut &= BitAND(BitShift($bTemp, $i), 1) Next Return $sOut EndFunc Func _StrBinary($sString) Local $Binary = "" For $I = 1 To StringLen($sString) $Binary &= _IntBinary(Asc(StringMid($sString, $I, 1))) Next Return $Binary EndFunc Func _IntBinary($sInteger) If $sInteger <= 0 Then Return SetError(1,$sInteger,-1) Local $sParameter While $sInteger> 0 $sParameter &= Mod($sInteger, 2) $sInteger = _Quotient($sInteger, 2) WEnd $sParameter = _StringOpposite($sParameter) Return StringFormat("%08s", $sParameter) EndFunc Func _BinInteger($in) Local $sInteger, $x, $i = 1, $aTmp = StringSplit(_StringOpposite($in), "") For $x = 1 To $aTmp[0] $sInteger += $aTmp[$x] * $i*(2^($x-1)) Next $aTmp = 0 Return StringFormat('%d', $sInteger) EndFunc Func _StringOpposite($sString) Local $sLen=StringLen($sString),$sReturn For $i=$sLen To 1 Step -1 $sReturn&=StringMid($sString,$i,1) Next Return $sReturn EndFunc Func DoubleToBinaryString($dIN) $sRet = "" $sHex = StringSplit(VariableToHexS($dIN),"") For $i = 1 to 16 $sRet &= HexCToBinary("0x" & $sHex[$i]) ;0x needed to correctly get autoit working with hex Next Return $sRet EndFunc Func VariableToHexS($dIn) Return Hex($dIn,16) EndFunc Func HexCToBinary($hIn) $sStr = "" For $i = 3 to 0 step -1 $sStr &= BitAnd(BitShift($hIn,$i),1) Next Return $sStr EndFunc ConsoleWrite(_StrBinary(8.2)&@CRLF) ConsoleWrite(_DoubleToBin(8.2)&@CRLF) ConsoleWrite(DoubleToBinaryString(8.2)&@CRLF)the above code requires My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
Shaggi Posted June 11, 2012 Share Posted June 11, 2012 (edited) Trancexx' and mine are correct. you can use this for reference:http://www.binaryconvert.com/result_double.html?decimal=056046050Edit: seems your first two truncates to single precision.Edit2: Notice the quote in your link: "The conversion is limited to single precision numbers (32 Bit)". Autoit only uses double-precision floating point numbers, which are 64 bits wide. Edited June 11, 2012 by Shaggi Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
PhoenixXL Posted June 11, 2012 Author Share Posted June 11, 2012 (edited) Notice the quote in your link: "The conversion is limited to single precision numbers (32 Bit)". Autoit only uses double-precision floating point numbers, which are 64 bits wide. Thnx Shaggi i didnt noticed that Thnx to M23 , Tracexx too Herez the working code i.e. of Trancexx and Shaggi Func _DoubleToBin($fValue) $fValue = Dec(Hex(Number($fValue, 3))) Local $bTemp = BinaryMid($fValue, 5, 4) Local $sOut For $i = 31 To 0 Step -1 $sOut &= BitAND(BitShift($bTemp, $i), 1) Next $bTemp = BinaryMid($fValue, 1, 4) For $i = 31 To 0 Step -1 $sOut &= BitAND(BitShift($bTemp, $i), 1) Next Return $sOut EndFunc Func DoubleToBinaryString($dIN) $sRet = "" $sHex = StringSplit(VariableToHexS($dIN),"") For $i = 1 to 16 $sRet &= HexCToBinary("0x" & $sHex[$i]) ;0x needed to correctly get autoit working with hex Next Return $sRet EndFunc Func VariableToHexS($dIn) Return Hex($dIn,16) EndFunc Func HexCToBinary($hIn) $sStr = "" For $i = 3 to 0 step -1 $sStr &= BitAnd(BitShift($hIn,$i),1) Next Return $sStr EndFunc Edited June 11, 2012 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
PhoenixXL Posted June 11, 2012 Author Share Posted June 11, 2012 For Debugging i made Float and Double data types using dllstruct create expandcollapse popup#include <String.au3> Func _StrBinary($sString) Local $Binary = "" For $I = 1 To StringLen($sString) $Binary &= _IntBinary(Asc(StringMid($sString, $I, 1))) Next Return $Binary EndFunc Func _IntBinary($sInteger) If $sInteger <= 0 Then Return SetError(1,$sInteger,-1) Local $sParameter While $sInteger> 0 $sParameter &= Mod($sInteger, 2) $sInteger = Floor($sInteger/2) WEnd $sParameter = _StringOpposite($sParameter) Return StringFormat("%08s", $sParameter) EndFunc Func _BinInteger($in) Local $sInteger, $x, $i = 1, $aTmp = StringSplit(_StringOpposite($in), "") For $x = 1 To $aTmp[0] $sInteger += $aTmp[$x] * $i*(2^($x-1)) Next $aTmp = 0 Return StringFormat('%d', $sInteger) EndFunc Func _StringOpposite($sString) Local $sLen=StringLen($sString),$sReturn For $i=$sLen To 1 Step -1 $sReturn&=StringMid($sString,$i,1) Next Return $sReturn EndFunc Func _DoubleToBin($fValue) $fValue = Dec(Hex(Number($fValue, 3))) Local $bTemp = BinaryMid($fValue, 5, 4) Local $sOut For $i = 31 To 0 Step -1 $sOut &= BitAND(BitShift($bTemp, $i), 1) Next $bTemp = BinaryMid($fValue, 1, 4) For $i = 31 To 0 Step -1 $sOut &= BitAND(BitShift($bTemp, $i), 1) Next Return $sOut EndFunc Func DoubleToBinaryString($dIN) $sRet = "" $sHex = StringSplit(VariableToHexS($dIN),"") For $i = 1 to 16 $sRet &= HexCToBinary("0x" & $sHex[$i]) ;0x needed to correctly get autoit working with hex Next Return $sRet EndFunc Func VariableToHexS($dIn) Return Hex($dIn,16) EndFunc Func HexCToBinary($hIn) $sStr = "" For $i = 3 to 0 step -1 $sStr &= BitAnd(BitShift($hIn,$i),1) Next Return $sStr EndFunc Local $sStruct=DllStructCreate('float;double'),$sLocale DllStructSetData($sStruct,1,8.2) DllStructSetData($sStruct,2,8.2) $1=DllStructGetData($sStruct,1) ;Float $2=DllStructGetData($sStruct,2) ;Double For $x=1 To 2 If $x=1 Then $sLocale='Float' If $x=2 Then $sLocale='Double' ConsoleWrite('Func_Name: _StrBinary'&@TAB&@TAB&' Type:'&$sLocale&' Value:'&_StrBinary(Eval($x))&@CRLF) ConsoleWrite('Func_Name: _DoubleToBin'&@TAB&@TAB&' Type:'&$sLocale&' Value:'&_DoubleToBin(Eval($x))&@CRLF) ConsoleWrite('Func_Name: DoubleToBinaryString'&@TAB&' Type:'&$sLocale&' Value:'&DoubleToBinaryString(Eval($x))&@CRLF&@CRLF&@CRLF) Next My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. 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