raw.convert编写的一个数值类型转换小程序
By
admin
at 2018-01-07 • 0人收藏 • 1367人看过
转换数据类型
raw.convert(from[,tostruct])
将from参数转换为tostruct类型。并返回tostruct.
from参数可以是一个指针、或结构体、或普通字符串
raw.cast = function( ctype,v ) begin var union_ctype = { union u= { byte byte =0; BYTE ubyte =0; word word =0; WORD uvord =0; int int =0; INT uint =0; long long =0; LONG ulong =0; double double =0; float float =0 } } return raw.convert( { long x= v }, union_ctype ).u[ctype]; end; namespace raw { byte = "byte"; BYTE = "ubyte"; word = "word"; WORD = "uvord"; int = "int"; INT = "uint"; long = "long"; LONG = "ulong"; double = "double"; float = "float" } //将-1转换为无符号数 uchr = raw.cast( raw.BYTE , -1 ); io.open(); io.print( uchr ); //显示255,转换成功
登录后方可回帖