;调用测试示例 a := ClipboardAll ;赋值 ;两种方法测试耗时 oldtime := A_TickCount test1 := HexOut(a) ;方法1 time1 := A_TickCount-oldtime oldtime := A_TickCount test2 := HexOut2(a) ;方法2 time2 := A_TickCount-oldtime ;MsgBox, 64, 提示, 方法1:%test1%`n耗时:%time1%ms`n`n方法2:%test2%`n耗时:%time2%ms MsgBox, 64, 提示, 方法1耗时:%time1%ms`n`n方法2耗时:%time2%ms HexOut(var,h:=0){ u := A_IsUnicode ? 2 : 1 ;Unicode版ahk字符长度是2 hex := {0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,10:"A",11:"B",12:"C",13:"D",14:"E",15:"F"} ;预置0-F的十六进制值 Loop % StrLen(var) ;循环变量的长度/次 { char := NumGet(var, (A_index-1)*u, "UChar") ;内存读取无格式单字节Asc值 ;串接 out .= hex[Floor(char/16)] hex[mod(char,16)] ;十进制转十六进制 Floor向下取整第二位 mod取余数第一位 并分别十六进制 } if h = 1 Return "0x" out ;返回0xFF格式 Else Return out ;返回FF格式 } HexOut2(var,h:=0){ u := A_IsUnicode ? 2 : 1 Loop % StrLen(var) ;循环变量的长度/次 { char := NumGet(&var, (A_index-1)*u, "UChar") ;内存读取无格式单字节Asc值 ;串接十六进制 SetFormat, IntegerFast, hex StringReplace, char, char, 0x, , All SetFormat, IntegerFast, d out .= StrLen(char)=2 ? char : "0" char } if h = 1 Return "0x" out ;返回0xFF格式 Else Return out ;返回FF格式 }
60 queries in 1.711 seconds |