 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Maelgwyn Guest
|
Posted: Wed Sep 21, 2005 12:29 pm Post subject: Hexadecimal to Decimal Conversion Tool |
|
|
Just a simple code for easy conversion between hexadecimally notated and decimally notated digits. Particularly useful around the PostMessage and SendMessage functions.
I'm not sure if this is somehow obsolete or has already been done but if not, it should help.
| Code: | ; Not a complicated script but very useful
;_______________________________________________________________________________
; Usage: Follow the prompts and enter either a hexadecimal value, ie, an or many
; integer/s or alphabetical value/s (Between A-F) proceeded by the prefix,
; 0x (Zero Multiplied By). For example, 0x8 OR/ 0xFFACD. Or a ; ; decimal ;value
; such as 987 or 250.
;_______________________________________________________________________________
;
;
;---------------------------------------------
;HOTKEY- (Feel free to change to your liking)
;---------------------------------------------
#p::
;---------------------------------------------
;HEX TO DECIMAL
;---------------------------------------------
MsgBox 4, Hexadecimal Conversion Tool,Hexadecimal to Decimal?
IfMsgBox, No
Gosub, Label1
IfMsgBox, Yes
InputBox, Hex1, Enter a Hexadecimal value
SetFormat, integer, decimal
Lolly -= 0
MsgBox, 0, Hexadecimal Conversion Tool, The Decimal value is %Hex1%
Exit
;---------------------------------------------
;DECIMAL TO HEX
;---------------------------------------------
Label1:
MsgBox, 4, Hexadecimal Conversion Tool, Decimal to Hexidecimal?
IfMsgBox, No
Exit
InputBox, Dec1, Enter a Decimal value
SetFormat, integer, hex
Lollies += 0
MsgBox, 0, Hexadecimal Conversion Tool, The Hexadecimal value is %Dec1% |
|
|
| Back to top |
|
 |
{Guest} Guest
|
Posted: Thu Sep 22, 2005 11:04 am Post subject: Hex/Dec Fix |
|
|
Not sure what's happened here Maelgwyn but this script appears to be some form of weird hybrid. I've repaired it and it seems to be functional now. I'll just post the new script to save time.
| Code: |
; Not a complicated script but very useful
;_______________________________________________________________________________
; Usage: Follow the prompts and enter either a hexadecimal value, ie, an or
many
; integer/s or alphabetical value/s (Between A-F) proceeded by the prefix,
; 0x (Zero Multiplied By). For example, 0x8 OR/ 0xFFACD. Or a ; ; decimal ;value
; such as 987 or 250.
;_______________________________________________________________________________
;
;
;---------------------------------------------
;HOTKEY- (Feel free to change to your liking)
;---------------------------------------------
#p::
;---------------------------------------------
;HEX TO DECIMAL
;---------------------------------------------
MsgBox 4, Hexadecimal Conversion Tool, Hexadecimal to Decimal?
IfMsgBox, No
Gosub, Label1
IfMsgBox, Yes
InputBox, Hex1, Enter a Hexadecimal value
SetFormat, integer, d
Hex1 -= 0
MsgBox, 0, Hexadecimal Conversion Tool, The Decimal value is %Hex1%
Exit
;---------------------------------------------
;DECIMAL TO HEX
;---------------------------------------------
Label1:
MsgBox, 4, Hexadecimal Conversion Tool, Decimal to Hexidecimal?
IfMsgBox, No
Exit
InputBox, Dec1, Enter a Decimal value
SetFormat, integer, h
Dec1 += 0
MsgBox, 0, Hexadecimal Conversion Tool, The Hexadecimal value is %Dec1%
|
Hope this helps.
!!Be sure to copy this script, not the one above!! |
|
| Back to top |
|
 |
TomB
Joined: 14 Jan 2005 Posts: 17
|
Posted: Wed Apr 25, 2007 1:27 pm Post subject: |
|
|
I realize this is a long time since the last message in this thread, but I decided to update this script slightly. The two main differences are:
1- There is now no message box asking you which way you want to convert - it just gives you in inputbox where you enter a dec or hex value (in 0x format) and the script determines which type you entered and converts it to the other.
2- The converted value is copied to the clipboard so you can easily paste it into an application.
Tom Boughner
| Code: |
; Not a complicated script but very useful
;_______________________________________________________________________________
; Usage: Enter either a decimal or hex value (must be preceded by 0x).
; The script will figure out which type you entered and convert it to the opposite.
; The converted value is displayed and placed on the clipboard.
;_________________________________________________________________
;---------------------------------------------
;HOTKEY- (Feel free to change to your liking)
;---------------------------------------------
#h::
;---------------------------------------------
;Get Input
;---------------------------------------------
InputBox, inp, Hexadecimal Conversion Tool, Enter a decimal value or a hexadecimal value in '0x' format
StringLeft HorD, inp, 2 ;get left-most two characters
if (HorD = "0x") ;Hex value entered
{
SetFormat, integer, d
inp -= 0
clipboard = %inp%
MsgBox, 0, Hexadecimal Conversion Tool, The Decimal value is %inp%
}
else
{
SetFormat, integer, h
inp += 0
clipboard = %inp%
MsgBox, 0, Hexadecimal Conversion Tool, The Hexadecimal value is %inp%
}
return
|
|
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Wed Apr 25, 2007 3:42 pm Post subject: |
|
|
It could be useful. Btw, you can save a few lines with the newer AHK features | Code: | #h::
InputBox inp, Hexadecimal Conversion Tool, Enter a decimal value or a hexadecimal value in '0x' format,,,170
SetFormat Integer, % SubStr(inp,1,2) = "0x" ? "D" : "H"
MsgBox 0, Hexadecimal Conversion, % "The converted value is " clipboard := inp+0
Return |
|
|
| Back to top |
|
 |
TomB
Joined: 14 Jan 2005 Posts: 17
|
Posted: Fri Apr 27, 2007 2:11 am Post subject: |
|
|
Wow - very cool. Can you optimize all of my code for me?
I am a novice programmer, so I haven't gotten too terribly advanced with AHK - but seeing your optimization opened my eyes to at least one area where I can save myself some keystrokes. Thanks Laszlo.
TomB |
|
| Back to top |
|
 |
Riddick51PB
Joined: 22 Apr 2007 Posts: 10 Location: Lincoln.ne.us
|
Posted: Sat Apr 28, 2007 3:38 pm Post subject: |
|
|
| windows hex calculator: Start, Run, calc [Enter], View, Scientific |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Sat Apr 28, 2007 3:58 pm Post subject: |
|
|
| Riddick51PB wrote: | | windows hex calculator: Start, Run, calc [Enter], View, Scientific | You can assign these to a hotkey (otherwise it is many keystrokes or mouse clicks), but doing this way takes a couple of seconds, while the AHK solution is practically instantaneous. You can also easily adapt the AHK version to your needs, like 4-8-16 hex digits with padding, lower case or capital letters, etc. |
|
| Back to top |
|
 |
Guest
|
Posted: Sat Apr 28, 2007 7:43 pm Post subject: |
|
|
| using hotkey to perform that would require excessive cpu and memory resources. |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Sat Apr 28, 2007 8:03 pm Post subject: |
|
|
| Anonymous wrote: | | using hotkey to perform that would require excessive cpu and memory resources. | It is not the case, if you have more hotkeys. Each one adds just a few bytes, and no measurable processor load. |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7290 Location: Australia
|
Posted: Mon Apr 30, 2007 4:16 am Post subject: |
|
|
| Laszlo wrote: | | Riddick51PB wrote: | | windows hex calculator: Start, Run, calc [Enter], View, Scientific | You can assign these to a hotkey (otherwise it is many keystrokes or mouse clicks), but doing this way takes a couple of seconds, while the AHK solution is practically instantaneous. You can also easily adapt the AHK version to your needs, like 4-8-16 hex digits with padding, lower case or capital letters, etc. |
I agree with you about the formatting customization (in particular, I think an automatic 0x prefix would be useful), however I find my own (calc!) method to be faster.
I have a calculator button (Launch_App2) on my keyboard, directly above the numpad. I'm much faster entering numbers with the numpad, so moving my hand from the mouse, to #h, then back to the numpad (or using the number keys) would be inefficient.
To convert to hex, I simply:
- Hit calc button.
- Type a decimal number.
- Hit calc button again. (If calc is active, it toggles hex/dec mode - thanks to AHK!)
- Ctrl+C to copy (though I don't always want to put it on the clipboard.)
Can't get much faster than that...
Except with hex->dec conversion: I use Numpad0 as a modifier to enter hex digits with the numpad (1-6 become A-F.)
Reading this thread has given me an idea... Override ^c in calc to custom-format hexadecimal numbers.  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|