Jump to content

..


Recommended Posts

I'm not sure what the Binary function returns, but you need to put quotes around the number in the first line to get to correct number returned. One thing I can tell you though, 4617878467915022336 does not equal 1640 in binary, or even in hex for that matter.

What exactly IS the result of the Binary function returning? The help file is extremely vague as to the return value, and the value returned doesn't make any sense to me.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I don't know that Binary() accepts INT64 types for integer inputs. Hex(), for example, only accepts INT32. You would have to do a decimal to hex conversion then pass the hex string to Binary():

$iVal = 4617878467915022336
ConsoleWrite("$iVal = " & $iVal & "; Type = " & VarGetType($iVal) & @LF)

$sVal = ""
While 1
    $iMod = Mod($iVal, 16)
    $sVal = $iMod & $sVal
    $iVal = Floor($iVal / 16)
    If Not $iVal Then ExitLoop
WEnd
$sVal = "0x" & $sVal
ConsoleWrite("$sVal = " & $sVal & "; Type = " & VarGetType($sVal) & @LF)

$bVal = Binary($sVal)
ConsoleWrite("$bVal = " & $bVal & "; Type = " & VarGetType($bVal) & @LF)

Result:

$iVal = 4617878467915022336; Type = Int64
$sVal = 0x4016000000001110; Type = String
$bVal = 0x4016000000001110; Type = Binary

:x

Edited 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
Link to comment
Share on other sites

I don't know that Binary() accepts INT64 types for integer inputs.

It will.

Binary(<i32>) := <b32i>[0x87654321]

Binary(<i64>) := <b64i>[0x8765432187654321]

Int(<b32i>) := <i32>[0x1234...]

Int(<b64i>) := <i64>[0x1234...]

note: use int(), number() is slightly bugged.

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Your code is interesting though. If it weren't for those three 1s at the end of those variables, they would be an endian swapped match for my expected output.

Side effect of float/double to int conversion. (becomes a risk when dealing with int values above, I think is was, 2^40)

$iVal = Floor($iVal / 16)

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

;; int32
$iTmp = 0x1234 ;; 4660 {I3} (0x00.00.12.34)
$bTmp = Binary($iTmp) ;; 0x34120000 {bn}(4)
$iTmp = Int($bTmp) ;; 4660 {I3} (0x00.00.12.34)
;; rev byte order.
$sTmp = String($bTmp) ;; "0x34120000" {St}
$iTmp = Number($sTmp) ;; 873594880 {I3} (0x34.12.00.00)
$iTmp = Number(String(Binary($iTmp))) ;; 4660 {I3} (0x00.00.12.34)

;; int64
$iTmp = Int("0x1234") ;; 4660 {I6} (0x00.00.00.00.00.00.12.34)
$bTmp = Binary($iTmp) ;; 0x3412000000000000 {bn}(8)
$iTmp = Int($bTmp) ;; 4660 {I6} (0x00.00.00.00.00.00.12.34)
;; rev byte order.
$sTmp = String($bTmp) ;; "0x3412000000000000" {St}
$iTmp = Number($sTmp) ;; 3752061439553044480 {I6} (0x34.12.00.00.00.00.00.00)
;~ $iTmp = Number(String(Binary($iTmp))) ;; 0 -> bugged.
$iTmp = int(String(Binary($iTmp))) ;; 4660 {I6} (0x00.00.00.00.00.00.12.34) ...

Edited by iEvKI3gv9Wrkd41u

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Okay, now that we've determined Binary() works on a 64bit integer, can we figure out how to convert 0x0000000000001640 back to 4617878467915022336? Is it even possible?

Kinda stupid question considering my previous post. :x

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

  • Moderators

More than one way to skin a cat:

Global $s_val = _myBinary_ToInt64(Binary(4617878467915022336))
ConsoleWrite($s_val & @CRLF)


Func _myBinary_ToInt64($s_val)
    Local $t_int64 = DllStructCreate("int64")
    DllStructSetData($t_int64, 1, Binary($s_val))
    Return DllStructGetData($t_int64, 1)
EndFunc

Edit:

Changed func name and example; guess it helps to read the rest of the post than just the outcome desired :x

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

nevermind.

Edited by iEvKI3gv9Wrkd41u

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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