Jump to content

Recommended Posts

Posted

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.

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Posted

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.

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Posted

; 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.

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Posted

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)
Posted

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.

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...