LarryDalooza Posted August 18, 2008 Posted August 18, 2008 I have a number and I want to convert it to 4 bytes (for TCP) and then from 4bytes back to a number... so basically... $a = Binary(6000) How do I get $a to be an "Number" data type equal to 6000? $a = Binary(6000) ;do something to $a here to make it 6000 again... MsgBox(0,"",$a) should show a msgbox with "6000" in it. thanks guys... I may find it soon, but I just need some help in case I don't get it soon. Time crunch here... Lar. AutoIt has helped make me wealthy
Developers Jos Posted August 18, 2008 Developers Posted August 18, 2008 (edited) Something like this? $a = Binary(String(6000)) $a = BinaryToString($a) MsgBox(0, "", $a) Edited August 18, 2008 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
LarryDalooza Posted August 18, 2008 Author Posted August 18, 2008 Something like this? $a = Binary(String(6000)) $a = BinaryToString($a) MsgBox(0, "", $a)Almost, but I want it to fit into 4 bytes... so I send Binary(6000) ; 4 bytes via TCP And when I TCPRecv the 4 bytes I want to go back to a number 6000 so String(123456) would be 6 bytes Binary(123456) would be 4 bytes I confuse myself... I wonder if Bit...() functions are in order. Lar. AutoIt has helped make me wealthy
-Ultima- Posted August 18, 2008 Posted August 18, 2008 (edited) ; Integer Local $a = 123456 ConsoleWrite($a & @CRLF) ; To binary (4 bytes) $a = Binary("0x" & Hex($a)) ConsoleWrite($a & @CRLF) ; To integer $a = Dec(StringTrimLeft($a, 2)) ConsoleWrite($a & @CRLF) Edited August 18, 2008 by -Ultima- [ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]
PsaltyDS Posted August 18, 2008 Posted August 18, 2008 (edited) Edit: NVM - You want little-endian byte-ordered fancy whizbang... as provided by SkinnyWhiteGuy. Edited August 18, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
LarryDalooza Posted August 18, 2008 Author Posted August 18, 2008 ; Integer Local $a = 123456 ConsoleWrite($a & @CRLF) ; To binary (4 bytes) $a = Binary("0x" & Hex($a)) ConsoleWrite($a & @CRLF) ; To integer $a = Dec(StringTrimLeft($a, 2)) ConsoleWrite($a & @CRLF) Would work, I suppose, but then I would impose on the client the need to do... $a = BinaryLen($SomeData) SendData(Binary("0x" & Hex($a))) Instead of... $a = BinaryLen($SomeData) SendData(Binary($a)) I am hoping for a simple intuitive... $a = Binary(12345) MsgBox(0,"",Bin2Int($a)) Lar. AutoIt has helped make me wealthy
SkinnyWhiteGuy Posted August 18, 2008 Posted August 18, 2008 This is probably the beast you were trying to avoid, but it does what you want it to... $dllStruct1_Integer = DllStructCreate("int") $dllStruct1_Binary = DllStructCreate("byte[4]", DllStructGetPtr($dllStruct1_Integer)) DllStructSetData($dllStruct1_Integer,1,6000) $a = DllStructGetData($dllStruct1_Binary, 1) ConsoleWrite($a & @CRLF) $dllStruct2_Integer = DllStructCreate("int") $dllStruct2_Binary = DllStructCreate("byte[4]", DllStructGetPtr($dllStruct2_Integer)) DllStructSetData($dllStruct2_Binary,1,Binary("0x71170000")) ; 1 more than 6000, Little-Endian Order $b = DllStructGetData($dllStruct2_Integer, 1) ConsoleWrite($b & @CRLF)
LarryDalooza Posted August 18, 2008 Author Posted August 18, 2008 This is probably the beast you were trying to avoid, but it does what you want it to... $dllStruct1_Integer = DllStructCreate("int") $dllStruct1_Binary = DllStructCreate("byte[4]", DllStructGetPtr($dllStruct1_Integer)) DllStructSetData($dllStruct1_Integer,1,6000) $a = DllStructGetData($dllStruct1_Binary, 1) ConsoleWrite($a & @CRLF) $dllStruct2_Integer = DllStructCreate("int") $dllStruct2_Binary = DllStructCreate("byte[4]", DllStructGetPtr($dllStruct2_Integer)) DllStructSetData($dllStruct2_Binary,1,Binary("0x71170000")) ; 1 more than 6000, Little-Endian Order $b = DllStructGetData($dllStruct2_Integer, 1) ConsoleWrite($b & @CRLF)oÝ÷ Ûú®¢×)¶"ëvØb±«¢+ÙÕ¹ ¥¸É9Õ´ ÀÌØìÑåÑ̤($ÀÌØí±±MÑÉÕÐÉ}%¹ÑÈô±±MÑÉÕÑ ÉÑ ÅÕ½Ðí¥¹ÐÅÕ½Ðì¤($ÀÌØí±±MÑÉÕÐÉ} ¥¹Éäô±±MÑÉÕÑ ÉÑ ÅÕ½ÐíåÑlÑtÅÕ½Ðì°±±MÑÉÕÑÑAÑÈ ÀÌØí±±MÑÉÕÐÉ}%¹ÑȤ¤((%±±MÑÉÕÑMÑÑ ÀÌØí±±MÑÉÕÐÉ} ¥¹Éä°Ä°ÀÌØìÑåÑ̤(%IÑÕɸ±±MÑÉÕÑÑÑ ÀÌØí±±MÑÉÕÐÉ}%¹ÑȰĤ)¹Õ¹ Thanks!!! Lar. AutoIt has helped make me wealthy
SkinnyWhiteGuy Posted August 18, 2008 Posted August 18, 2008 No problem, it's the way I figured to mimic Python's pack/unpack for a project I'm working on. Also makes a for a poor man's union, when you have to do something like that.
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