mmavipc Posted October 7, 2008 Share Posted October 7, 2008 Hey Does anyone have a Binary to number function? the binarytostring function does not return a number I have $b = Binary(256) i need to retrieve the 256 later. Heres my current non-working test code $b = binary(256) MsgBox(0,"",$B) $b = BinaryToString($B) MsgBox(0,"",$B) $b = asc($B) MsgBox(0,"",$B) Thanks in advanced [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N Link to comment Share on other sites More sharing options...
Richard Robertson Posted October 7, 2008 Share Posted October 7, 2008 Have you tried using Number($? Link to comment Share on other sites More sharing options...
ken82m Posted October 7, 2008 Share Posted October 7, 2008 (edited) Here's an exmaple script on how to do it.http://www.autoitscript.com/forum/lofivers...php?t70507.htmlI cut out the section of code below that should be all you need.I tested this myself and it worked great.-Kenny#include <String.au3> $BinaryString = InputBox("Test", "Enter Binary Number to Convert") $Converted = _BinaryToDec($BinaryString) MsgBox(4096,"Test", "Converted Number: " & $Converted) Func _BinaryToDec($strBin) Local $Return Local $lngResult Local $intIndex If StringRegExp($strBin,'[0-1]') then $lngResult = 0 For $intIndex = StringLen($strBin) to 1 step -1 $strDigit = StringMid($strBin, $intIndex, 1) Select case $strDigit="0" ; do nothing case $strDigit="1" $lngResult = $lngResult + (2 ^ (StringLen($strBin)-$intIndex)) case else ; invalid binary digit, so the whole thing is invalid $lngResult = 0 $intIndex = 0; stop the loop EndSelect Next $Return = $lngResult Return $Return Else MsgBox(0,"Error","Wrong input, Conversion Failed, try again ...") Exit Return EndIf EndFunc Edited October 7, 2008 by ken82m "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains." Link to comment Share on other sites More sharing options...
Malkey Posted October 7, 2008 Share Posted October 7, 2008 Hey Does anyone have a Binary to number function? the binarytostring function does not return a number I have $b = Binary(256) i need to retrieve the 256 later. Heres my current non-working test code $b = binary(256) MsgBox(0,"",$B) $b = BinaryToString($B) MsgBox(0,"",$B) $b = asc($B) MsgBox(0,"",$B)oÝ÷ Ù8ZK"§ojwwú®¢×+,y鬶(®F®¶sbb33c¶"Ò&æ'gV÷C³gV÷C²fײW#Sb¤×6t&÷ÂgV÷C²gV÷C²Âb33c¶" ¢b33c¶"ÒFV2Wb33c¶"¤×6t&÷ÂgV÷C²gV÷C²Âb33c¶" Link to comment Share on other sites More sharing options...
mmavipc Posted October 7, 2008 Author Share Posted October 7, 2008 (edited) Nethire of yours works. Both return 0 Ken82n's sort of works but it wont work with a 0x infront of the binary(autoit style) And number doesnt work for numbers higher than 255 edit: @malkey i need it to be [psuedocode]binary(number)[/psuedocode] and thats all for declasing $b initially Edited October 7, 2008 by mmavipc [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N Link to comment Share on other sites More sharing options...
ken82m Posted October 7, 2008 Share Posted October 7, 2008 It worked ok for me. Give me the number your trying to convert and the result your expect.Thanks,KennyNethire of yours works. Both return 0Ken82n's sort of works but it wont work with a 0x infront of the binary(autoit style)And number doesnt work for numbers higher than 255 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains." Link to comment Share on other sites More sharing options...
Richard Robertson Posted October 7, 2008 Share Posted October 7, 2008 That's odd that Number would cut off at 255. I'm sure there's a reason somewhere. Link to comment Share on other sites More sharing options...
mmavipc Posted October 7, 2008 Author Share Posted October 7, 2008 (edited) It worked ok for me. Give me the number your trying to convert and the result your expect. Thanks, Kennybinary: 0x00010000 expected: 256 edit: @Richard: the test code I used for your soulution was $b = binary(256) MsgBox(0,"",$B) ;~ $b = BinaryToString($B) ;~ MsgBox(0,"",$B) $b = Number($B) MsgBox(0,"",$B) msgbox(0,";dfk",Number(binary(256))) try it yourself edit @malkey: The reason that I need it to be binary(number) is becuase the binary is generated by tcprecv. Edited October 7, 2008 by mmavipc [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N Link to comment Share on other sites More sharing options...
ken82m Posted October 7, 2008 Share Posted October 7, 2008 (edited) hmmm your a little beyond me I'm afraid. According to the online converter I'm using 256 = 100000000 Do you have the TCPRECV command flagged with 1 to force binary? Edited October 7, 2008 by ken82m "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains." Link to comment Share on other sites More sharing options...
mmavipc Posted October 7, 2008 Author Share Posted October 7, 2008 hmmm your a little beyond me I'm afraid. According to the online converter I'm using 256 = 100000000Thats regular binary not au3 binary [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N Link to comment Share on other sites More sharing options...
Nevin Posted October 7, 2008 Share Posted October 7, 2008 What the heck is au3 binary? P.S. You wrote 0x, which is the prefix for hex, isnt it? But that number following it is 65536 (decimal) Link to comment Share on other sites More sharing options...
ken82m Posted October 7, 2008 Share Posted October 7, 2008 (edited) What the heck is au3 binary?P.S. You wrote 0x, which is the prefix for hex, isnt it? But that number following it is 65536 (decimal)That's what I was thinking but he's right binary(256) returns the 0x number he provided. But i can't find any forumla using hex or bin to get it back to 256.I can't find anyway to get any of these conversions autoit is doing to match up to any math I've learned.... Edited October 7, 2008 by ken82m "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains." Link to comment Share on other sites More sharing options...
Community On Patrol Posted October 7, 2008 Share Posted October 7, 2008 Hi mmavipc, Please create descriptive topics. Using one word topics makes it really difficult to use the search feature, and those that could probably answer your question will probably not even read your thread. Doing it enough could cause your posting privileges to be taken away all together, and we don't want that . Thanks. Link to comment Share on other sites More sharing options...
Malkey Posted October 7, 2008 Share Posted October 7, 2008 (edited) Try this one. Local $b = Binary(256) MsgBox(0, "", $B) Local $a = Bin2Num($B) MsgBox(0, "", $a) Func Bin2Num($4Bytes) Local $dllStruct2_Integer = DllStructCreate("int") Local $dllStruct2_Binary = DllStructCreate("byte[4]", DllStructGetPtr($dllStruct2_Integer)) DllStructSetData($dllStruct2_Binary, 1, $4Bytes) Return DllStructGetData($dllStruct2_Integer, 1) EndFunc ;==>Bin2Num Edited October 7, 2008 by Malkey Link to comment Share on other sites More sharing options...
ken82m Posted October 7, 2008 Share Posted October 7, 2008 (edited) Nice! I was trying to find some commands relating to bytes just as an idea earlier but found nothing. I damn well wouldn't have come up with that one. Something similiar should be added as a built in function. Good one for the Example forum if it's not already there. -Kenny Try this one. Local $b = Binary(256) MsgBox(0, "", $B) Local $a = Bin2Num($B) MsgBox(0, "", $a) Func Bin2Num($4Bytes) Local $dllStruct2_Integer = DllStructCreate("int") Local $dllStruct2_Binary = DllStructCreate("byte[4]", DllStructGetPtr($dllStruct2_Integer)) DllStructSetData($dllStruct2_Binary, 1, $4Bytes) Return DllStructGetData($dllStruct2_Integer, 1) EndFunc ;==>Bin2Num Edited October 7, 2008 by ken82m "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains." Link to comment Share on other sites More sharing options...
mmavipc Posted October 8, 2008 Author Share Posted October 8, 2008 Try this one. Local $b = Binary(256) MsgBox(0, "", $B) Local $a = Bin2Num($B) MsgBox(0, "", $a) Func Bin2Num($4Bytes) Local $dllStruct2_Integer = DllStructCreate("int") Local $dllStruct2_Binary = DllStructCreate("byte[4]", DllStructGetPtr($dllStruct2_Integer)) DllStructSetData($dllStruct2_Binary, 1, $4Bytes) Return DllStructGetData($dllStruct2_Integer, 1) EndFunc ;==>Bin2NumTHANK YOU SOO MUCH you are awsome [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N 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