Monday, December 5, 2011

AppleScript 에서 16진수를 10진수로 변환하는 방법?

질문 : AppleScript 에서 Hexadecimal <--> Decimal Conversion 하는 방법?
답 :
This code converts a decimal number into a hexdecimal string:
set nDec to 1000
set nHex to do shell script "perl -e 'printf(\"%x\", " & nDec & ")'" --> "3e8"

To get uppercase letters, use %X instead of %x
set nHex to do shell script "perl -e 'printf(\"%X\", " & nDec & ")'" --> "3E8"

To get additional leading zeros, use e.g. %04X for "add zeros for four-digit output"
set nHex to do shell script "perl -e 'printf(\"%04X\", " & nDec & ")'" --> "03E8"

And this code converts a hexdecimal string into a decimal number:
set nHex to "03E8"
set nDec to (do shell script "perl -e 'printf(hex(\"" & nHex & "\"))'") as number --> 1000

레퍼런스 : http://macscripter.net/viewtopic.php?id=19442

No comments:

Post a Comment