AppleScript名:16進数文字列とNumberの相互変換 v2.2 |
— Created 2018-01-20 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" repeat with i from 0 to 65535 set aRes to numToHexl(i) of hexKit set bRes to hextoNum(aRes) of hexKit if i ≠ bRes then display dialog "Not equal to " & (i as string) & " —> " & aRes & " —> " & bRes end repeat script hexKit property hexList : {missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, 10, 11, 12, 13, 14, 15} property stringSetList : {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"} –16進数文字列からNumberに変換 on hextoNum(hexText as string) set hList to characters of hexText set rhList to reverse of hList set digitNum to 0 set sumNum to 0 repeat with i in rhList set j to id of contents of i if j > 102 then return false set ofN to contents of item j of hexList of me if ofN = missing value then return false set sumNum to sumNum + (16 ^ digitNum) * (ofN) set digitNum to digitNum + 1 end repeat return sumNum as integer end hextoNum –数値を16進数文字列に変換 on numToHexl(origNum) if origNum = 0 then return "0" set resString to {} repeat if origNum ≤ 0 then exit repeat set resNum to (origNum mod 16) set resText to contents of item (resNum + 1) of stringSetList set resString to resText & resString set origNum to origNum div 16 end repeat return (resString as string) end numToHexl end script |
More from my site
(Visited 27 times, 1 visits today)