Page 1 of 1

### Debugging: AHK decimal vs. spy tools hex

Posted: 07 Oct 2019, 13:56
In cases where AHK stores hwnd as decimal (which I believe is always in V2), what are you gurus who are using debuggers and spy tools using to easily convert between decimal and hex?

e.g. I'm using SciTE4AHK and Spy++/Control Viewer

Spy++/Control Viewer display hwnd in hex, but SciTE4AHK is displaying in decimal, so either I find myself being annoyed as I:
• Add temporary code to convert and store hwnds as hex so I can easily compare the spy tool and the AHK variable in the debugger, or
• Use a calculator to convert between the two, or...
So I'm wondering what others are doing to minimize the aggravation?

For those of you who can convert between decimal and hex in your head, no need to respond

### Re: Debugging: AHK decimal vs. spy tools hex

Posted: 07 Oct 2019, 15:20
I don't use any debug tools (by other people), and if I did, I'd edit them to show both dec and hex.

Code: Select all

``````vNum := 123
MsgBox, % Format("0x{:X}", vNum) ;0x7B
``````

### Re: Debugging: AHK decimal vs. spy tools hex

Posted: 07 Oct 2019, 15:36
Thanks - I wish they would do that!

Anyone else?

### Re: Debugging: AHK decimal vs. spy tools hex

Posted: 08 Oct 2019, 14:04
SAbboushi wrote:
07 Oct 2019, 13:56
For those of you who can convert between decimal and hex in your head, no need to respond
I take that back! How about:
For those of you who can convert decimal numbers greater than 6 bytes into hex in your head, no need to respond

Anyone?

### Re: Debugging: AHK decimal vs. spy tools hex

Posted: 08 Oct 2019, 14:54
SAbboushi wrote:
08 Oct 2019, 14:04
For those of you who can convert decimal numbers greater than 6 bytes into hex in your head, no need to respond
You mean 6 bits? Would anyone ever convert anything more than one byte in their head?

### Re: Debugging: AHK decimal vs. spy tools hex

Posted: 08 Oct 2019, 15:35
boiler wrote:
08 Oct 2019, 14:54
You mean 6 bits?
No -- I meant bytes
But I was kidding about 6 bytes
boiler wrote:
08 Oct 2019, 14:54
Would anyone ever convert anything more than one byte in their head?
Today, maybe not! Having programmed in assembly back in the 1970s, some of us old-timers got pretty good at converting more than 8 bits in our heads.
Heck - we didn't have internet and netflix in those days -- what else was there for us to do?!

Anyway, seems this post isn't getting any traction...

### Re: Debugging: AHK decimal vs. spy tools hex

Posted: 08 Oct 2019, 16:37
SAbboushi wrote: No -- I meant bytes
But I was kidding about 6 bytes
Oh, I see.
SAbboushi wrote: Anyway, seems this post isn't getting any traction...
I think it's probably because most people just end up using a calculator as you mentioned.

### Re: Debugging: AHK decimal vs. spy tools hex

Posted: 08 Oct 2019, 17:07
You could make a tool to automatically convert decimal numbers to hex, like this one. Any time the clipboard changes, if it contains text, it will convert the first number it encounters to hex and display it in a tooltip for a few seconds along with a reminder that it's ready to be pasted using Shift+Ctrl+v. The original clipboard contents remain unmodified, so they can still be pasted using Ctrl+v as usual.

Code: Select all

``````global num
OnClipboardChange("GetNum")

GetNum(type)
{
if (type != 1) ; clipboard empty or non-text
return

RegExMatch(Clipboard, "\d+", num)
if (num != "")
{
ToolTip, % "Paste " Format("{:#x}", num) " with Shift + Ctrl + v"
Sleep, 3000
ToolTip
}
}

+^v::Send, % Format("{:#x}", num)``````

### Re: Debugging: AHK decimal vs. spy tools hex

Posted: 08 Oct 2019, 18:17
Thanks!

### Re: Debugging: AHK decimal vs. spy tools hex

Posted: 09 Oct 2019, 14:40
Since my priority is ease of debugging and maintainability instead of performance, I've decided to store hwnds and styles as hex in my variables so I can easily compare values to debugging tools.

I then use Integer(hwnd) for those commands that require type Integer e.g.

Code: Select all

``hwndText := ControlGetText( Integer(hwnd) )``
It's a shame the debugging tools I use don't subscribe to jeeswg's philosophy: show both dec and hex (or give option to do so)

Hmmm... no smiley for "banging head against wall"...

### Re: Debugging: AHK decimal vs. spy tools hex

Posted: 09 Oct 2019, 14:54
There is no reason to convert the values within AHK. They are both integers, just expressed differently (either in decimal or hex). AHK will see 255 the same as 0xFF, for example. Just make sure to precede the hex numbers with 0x.

Edit: There are some instances, especially when expressing colors, where hex is required, but in terms of a value like an hwnd, you can just use the decimal value. Caveat: I have not used AHK v2 yet, but I wouldn't think it is more restrictive in this sense.

### Re: Debugging: AHK decimal vs. spy tools hex

Posted: 09 Oct 2019, 14:55
SAbboushi wrote:
09 Oct 2019, 14:40
Hmmm... no smiley for "banging head against wall"...
I guess you missed it:

### Re: Debugging: AHK decimal vs. spy tools hex

Posted: 09 Oct 2019, 18:22

Thanks again!!