AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Hexadecimal to Decimal Conversion Tool

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Maelgwyn
Guest





PostPosted: Wed Sep 21, 2005 12:29 pm    Post subject: Hexadecimal to Decimal Conversion Tool Reply with quote

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





PostPosted: Thu Sep 22, 2005 11:04 am    Post subject: Hex/Dec Fix Reply with quote

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

PostPosted: Wed Apr 25, 2007 1:27 pm    Post subject: Reply with quote

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
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Wed Apr 25, 2007 3:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
TomB



Joined: 14 Jan 2005
Posts: 17

PostPosted: Fri Apr 27, 2007 2:11 am    Post subject: Reply with quote

Wow - very cool. Can you optimize all of my code for me? Smile

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
View user's profile Send private message
Riddick51PB



Joined: 22 Apr 2007
Posts: 10
Location: Lincoln.ne.us

PostPosted: Sat Apr 28, 2007 3:38 pm    Post subject: Reply with quote

windows hex calculator: Start, Run, calc [Enter], View, Scientific
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Sat Apr 28, 2007 3:58 pm    Post subject: Reply with quote

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
View user's profile Send private message
Guest






PostPosted: Sat Apr 28, 2007 7:43 pm    Post subject: Reply with quote

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

PostPosted: Sat Apr 28, 2007 8:03 pm    Post subject: Reply with quote

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
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 7290
Location: Australia

PostPosted: Mon Apr 30, 2007 4:16 am    Post subject: Reply with quote

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:
  1. Hit calc button.
  2. Type a decimal number.
  3. Hit calc button again. (If calc is active, it toggles hex/dec mode - thanks to AHK!)
  4. 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.) Very Happy

Reading this thread has given me an idea... Override ^c in calc to custom-format hexadecimal numbers. Cool
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group