FILE名:FILE_char2int.hsp
注:このモジュールのTESTには
FILE_int2char.hsp
が必要です
#module char2int // 16進表記の引数(0〜15)を数値に変換して返す // 引数の長さが1でないとerror // 引数の値が0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,fの // どれかでないとerror #defcfunc one_at_char2int str cc f=0 ff=0 fff=0 l=strlen(cc) if l!=1{ logmes "one_at_char2int内のerror" logmes "文字列型引数ccの長さは1にして下さい" logmes "引数の長さ:"+l return -1 } if (cc=="0")|(cc=="1")|(cc=="2")|(cc=="3")|(cc=="4"){f=1} if (cc=="5")|(cc=="6")|(cc=="7")|(cc=="8")|(cc=="9"){ff=1} if (cc=="a")|(cc=="b")|(cc=="c")|(cc=="d")|(cc=="e")|(cc=="f"){fff=1} if (f==0)&(ff=0)&(fff=0){ logmes "one_at_char2int内のerror" logmes "引数は" logmes "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f" logmes "のどれかにして下さい" logmes "引数の値:"+cc return -1 } switch cc case "0":return 0 case "1":return 1 case "2":return 2 case "3":return 3 case "4":return 4 case "5":return 5 case "6":return 6 case "7":return 7 case "8":return 8 case "9":return 9 case "a":return 10 case "b":return 11 case "c":return 12 case "d":return 13 case "e":return 14 case "f":return 15 swend return -1 // 引数cを文字列に変換して返す // 引数cの値が0〜255でないとerror // 引数typeの値が2の時は16進の2桁の数字を返す // 引数typeの値が3の時は10進の3桁の数字を返す // 引数typeの値が2か3でないとerror #defcfunc some_at_char2int str c,int type if (type!=2)&(type!=3){ logmes "some_at_char2int内のerror" logmes "第二引数の値は2か3にして下さい" logmes "第二引数の値:"+str(type) return -1 } l=strlen(c) if (type==2)&(l!=2){ logmes "some_at_char2int内のerror" logmes "引数typeの値が2の場合は" logmes "文字列型引数cの長さは2にして下さい" logmes "引数の長さ:"+l logmes "引数の値:"+c return -1 } if (type==3)&(l!=3){ logmes "some_at_char2int内のerror" logmes "引数typeの値が3の場合は" logmes "文字列型引数cの長さは3にして下さい" logmes "引数の長さ:"+l logmes "引数の値:"+c return -1 } if type==2{ ccc=c n=strmid(ccc,0,1) m=strmid(ccc,1,1) mm= (one_at_char2int(n)*16)+(one_at_char2int(m)) mmm="" poke mmm,0,mm return mmm }else{ if type==3{ ccc=c mm=int(ccc) mmm="" poke mmm,0,mm return mmm } } return -1 #global s="abcde" logmes str(one_at_char2int(s)) s="ab" logmes str(one_at_char2int(s)) s="a" logmes str(one_at_char2int(s)) s="" logmes str(one_at_char2int(s)) s="abcde" logmes str(some_at_char2int(s,2)) s="ab" logmes str(some_at_char2int(s,2)) s="a" logmes str(some_at_char2int(s,2)) s="" logmes str(some_at_char2int(s,2)) ss="ABCabcdefghi0123456789|%$" l=strlen(ss) repeat l t=strmid(ss,cnt,1) logmes str(one_at_char2int(t)) loop #include "FILE_int2char.hsp";注 t="" repeat 300,-10 t=some_at_int2char(cnt,2) logmes str(some_at_char2int(t,2)) loop logmes "" repeat 300,-10 t=some_at_int2char(cnt,3) logmes str(some_at_char2int(t,3)) loop logmes "" t=some_at_int2char('a',2) logmes str(some_at_char2int(t,2)) t=some_at_int2char('b',2) logmes str(some_at_char2int(t,2)) t=some_at_int2char('c',2) logmes str(some_at_char2int(t,2)) t=some_at_int2char('d',2) logmes str(some_at_char2int(t,2)) t=some_at_int2char('e',2) logmes str(some_at_char2int(t,2)) t=some_at_int2char('a',3) logmes str(some_at_char2int(t,3)) t=some_at_int2char('b',3) logmes str(some_at_char2int(t,3)) t=some_at_int2char('c',3) logmes str(some_at_char2int(t,3)) t=some_at_int2char('d',3) logmes str(some_at_char2int(t,3)) t=some_at_int2char('e',3) logmes str(some_at_char2int(t,3)) t=some_at_int2char('3',2) logmes str(some_at_char2int(t,2)) t=some_at_int2char('$',2) logmes str(some_at_char2int(t,2)) t=some_at_int2char('?',2) logmes str(some_at_char2int(t,2)) t=some_at_int2char('\\',2) logmes str(some_at_char2int(t,2)) t=some_at_int2char('3',3) logmes str(some_at_char2int(t,3)) t=some_at_int2char('$',3) logmes str(some_at_char2int(t,3)) t=some_at_int2char('?',3) logmes str(some_at_char2int(t,3)) t=some_at_int2char('\\',3) logmes str(some_at_char2int(t,3)) |
注:このモジュールのTESTには
FILE_int2char.hsp
が必要です