




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
VB关于ASCII码转换成16进制的问题悬赏分:5 - 解决时间:2008-10-21 16:01 有这样一团代码:他能实现字符串转换成ASCII码16进制 但是我想让他实现ASCII码16进制转换成字符串 谢谢各位大哥 希望能有代码 并且给出比较详细的说明 我会追加积分的 麻烦了!Private Sub Command1_Click() Dim A$, i%, B$ A = Text1.Text For i = 1 To Len(A) B = B & Hex(Asc(Mid(A, i, 1) Next Text2.Text = B End Sub 建立两个文本框 一个按钮Private Sub Command1_Click() Dim A1%, B1$, i%, p% 定义变量 A1 = Text1.Text 将输入的ASCII码赋值给A1 For i = Len(A1) To 1 Step -1 循环 B1 = Mid(UCase(A1), i, 1) 取各位数字 为了方便转为大写 p = Len(A1) - i 位权 Select Case B1 将16进制转为10进制 Case AC = C + 16 p * 10 Case B C = C + 16 p * 11 Case C C = C + 16 p * 12 Case D C = C + 16 p * 13 Case E C = C + 16 p * 14 Case F C = C + 16 p * 15 Case Else C = C + 16 p * Val(B1) End Select Next Text2.Text = Chr(C) 转换为字符 End Sub以上是对你程序的修改的方法其实完全可以很简单的Private Sub Command1_Click()Dim A1%, B1$, i%, p% 定义变量A1 = Text1.Text 将输入的ASCII码赋值给A1Text2.Text = Chr(Val(&H & A1) 转换为字符 利用数值转换End Sub试试效果是不是一样啊求vb中将字符串转换为16进制的ascii码代码悬赏分:110 - 解决时间:2008-2-20 16:46 ascii码为16进制形式的字符串包含数字字母和汉字 问题补充:得到的ascii码全部为大写、并且取值是从后往前欢迎大家积极帮助积分定当顷囊相送楼上的不是VB代码,不要乱贴啊使用VB内部函数 Hex$(x) 是把10进制的数字变成16进制如y=Hex$(10)就是求10的十六进制数 那么 y=A字母,数字,和汉字的asc码都只要用asc()这个函数就可以求出来了你把问题写写清楚的话,我可以写下代码Option ExplicitDim aa$, bb$, hexstr$, I&, SPrivate Sub Command1_Click()Dim lendd As Integer, n As Integer lendd = Len(Text2.Text) Text3.Text = n = 0 For I = lendd To 1 Step -1 n = n + 1 Text3.Text = Text3.Text + Mid(Text2.Text, I, 1) If n = 4 Then Text3.Text = Text3.Text & -: n = 0 Next I End SubPrivate Sub command2_Click() aa = If Text1.Text = Then Exit Sub For I = 1 To Len(Text1.Text) aa = aa & CStr(ZFto16(Mid(Text1.Text, I, 1) Next I Text2.Text = Trim(aa) Text1.Text = End SubPublic Function ZFto16(hz$) As String If hz = Then Exit Function ZFto16 = Hex(Asc(hz)End FunctionPublic Function ZF16toZF(hexstr$) As String If hz = Then Exit Function ZF16toZF = Chr(&H & hexstr)End Function其他回答共 2 条int char2int(char ch) if(ch=0 & ch=a & ch=A & ch= F) return (ch-A+0xa); return -1; /*没处理非法字符,可以根据函数char2int()返回值处理*/ bool convert(char *dst, char *src) char *p=src; char *q=dst; int len = strlen(src); /*奇数长度,按右对齐方式处理*/ if(len%2) *q+ = char2int(*p+); while(*p) *q = char2int(*p+) =0)&(dat=4; dat=dat&0x0f; if(dat=0)&(dat=9) dat+=0x30; else dat+=0x37; UART_TX_buff8=dat; voidascii_to_hex(void) unsignedcharcnt,i; for(cnt=0,i=0;cnt6;cnt+,cnt+,i+) Twi_Hex_Datai=Twi_ASCI_Datacnt+1;/先放ASCII的高位(四位) Twi_Hex_Datai=4; Twi_Hex_Datai+=Twi_ASCI_Datacnt; #defineHex2Ascii(data)(data4; pBuf0=Hex2Ascii(temp); 这个短点再加上两字节的: #defineHex2Ascii(data)(data4; pBuf0=Hex2Ascii(temp); voidUint2ASCII(unsignedshortdata,unsignedchar*pBuf) unsignedchartemp; temp=(unsignedchar)(data&0x000F); pBuf3=Hex2Ascii(temp); data=4; temp=(unsignedchar)(data&0x000F); pBuf2=Hex2Ascii(temp); data=4; temp=(unsignedchar)(data&0x000F); pBuf1=Hex2Ascii(temp); data=4; temp=(unsignedchar)(data); pBuf0=Hex2Ascii(temp); #defineAscii2Hex(data)(data=0&data=A&data=a&data=f)?(data-a+10):0) unsignedcharASCII2Byte(unsignedchar*pBuf) unsignedchartemp; unsignedcharc; c=*pBuf+; temp=(unsignedchar)Ascii2Hex(c)4; c=*pBuf; temp+=Ascii2Hex(c); returntemp; unsignedshortASCII2Uint(unsignedchar*pBuf) unsignedshorttemp; unsignedcharc; c=*pBuf+; temp=(unsignedshort)Ascii2Hex(c)12; c=*pBuf+; temp+=(unsignedshort)Ascii2Hex(c)8; c=*pBuf+; temp+=(unsignedshort)Ascii2Hex(c)4; c=*pBuf; temp+=Ascii2Hex(c); returntemp; Dim str As String Dim dst As String str = 4e str = &h + strdst = ChrW(Val(str)Option ExplicitPrivate Sub Command1_Click() Dim cHex As String, S As String, HexStr As String Dim i As Long cHex = 4e323830372e34303039324531323131332e3936313739 For i = 1 To Len(cHex) Step 2 S = &H & Mid$(cHex, i, 2) HexStr = HexStr & Chr$(CLng(S) Next Debug.Print HexStrEnd SubOption ExplicitPrivate Sub Command1_Click() Dim byteHEX() As Byte Dim strP As String Dim intP As Integer strP = Text1.Text intP = Len(strP) If intP Mod 2 0 Then strP = 0 & strP intP = intP / 2 ReDim byteHEX(intP) Text2.Text = For intP =我的函数是Public Function GbkStr(ByVal ss As String) As StringOn Error Resume NextDim x As StringDim Y As VariantDim i As IntegerDim j As IntegerReDim b(0 To (Len(ss) / 2) As Bytej = 0For i = 1 To Len(ss)x = Mid$(Trim(ss), i, 2)Y = CLng(&H & x)If Y 0 Then Y = Y + 65536b(j) = Yi = i + 1j = j + 1Next i GbkStr = StrConv(b, vbUnicode)End Function请问具体该怎么做啊?If Y 0 Then Y = Y + 65536再判断一下是否是不可显示的字符(H0H20),如果是,则转成.我写的能显示中文,虽然有时有乱码.因为是写的共用函数里的部分,在调用时不需要使用,所以用了条件编译.CopyMemory 是API函数,声明如下:程序代码:Public Declare Sub CopyMemory Lib kernel32 Alias RtlMoveMemory (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)程序代码: #If tools Then 工具显示16进制代码 With Form1.Text3Dim txj As StringDim txj2 As StringDim txj3 As StringDim txp As BooleanDim txj4 As IntegerDim txk(1) As Byte.Text = 加密结果 & vbCrLf & 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0FFor i = 0 To optr - 1.Text =.Text & vbcrlf &txj = Hex(pout(i)If Len(txj) = 1 Then txj = 0 & txjtxj2 = txj2 & & txj 这是生成16进制部分If pout(i) = 32 Then可显示字符txj3 = txj3 & Chr(pout(i) Elsetxj3 = txj3 & . End IfElse If Not txp Then是否上一个字符输出时,取走了这个字符,否,输出中文txk(1) = pout(i)txk(0) = pout(i + 1)CopyMemory txj4, txk(0), 2txj3 = txj3 & Chr(txj4)txp = True设置取走了下一个字符 Elsetxp = False End IfEnd IfIf (i + 1) Mod 16 = 0 Then 换行,按每行16个字节排列 txj = 0 & i 16 txj = String(4 - Len(txj), 0) & txj .Text = .Text & vbCrLf & txj & & txj2 & & txj3 txj2 = txj3 = End If Next i txj = 0 & i 16最后一行的显示 txj = String(4 - Len(txj), 0) & txj .Text = .Text & vbCrLf & txj & & txj2 & Space(48 - Len(txj2) & & txj3 End With 工具输出结束 #End IfC/C+ ASCII转HEX和HEX转ASCII 算法void hex_to_ascii(unsigned char dat) unsigned char dat_buff; dat_buff = dat; dat = dat
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年区块链金融行业应用前景研究报告
- 2025年医疗健康行业智能医疗设备市场前景展望报告
- 国家事业单位招聘2025国家海洋标准计量中心招聘应届毕业生拟聘人员笔试历年参考题库附带答案详解
- 吉林省2025年吉林白城通榆县事业单位引进急需紧缺人才笔试历年参考题库附带答案详解
- 南宁市2025广西南宁市青秀区委政法委招聘2人笔试历年参考题库附带答案详解
- 克拉玛依市2025新疆克拉玛依市企事业单位高层次急需紧缺人才引进(493人)笔试历年参考题库附带答案详解
- 乌兰察布市2025内蒙古乌兰察布市四子王旗高层次和紧缺急需人才引进46人笔试历年参考题库附带答案详解
- 2025重庆国咨数据服务有限公司招聘18人笔试参考题库附带答案详解
- 2025甘肃张掖市发展投资集团有限公司招聘专业技术人员6人笔试参考题库附带答案详解
- 2025河南空港数字城市开发建设有限公司第一批社会招聘20人笔试参考题库附带答案详解
- 危重患者皮肤管理课件
- 2025年国防教育知识竞赛试题(附答案)
- 工伤受伤经过简述如何写
- 银行现金取款申请书
- 人事外包招聘代理合同
- 数字经济学-课件 第3章 数字技术
- AI引领时尚设计新潮-个性化需求的新一代解决方案
- 高二数学直线倾斜角与斜率同步练习题
- 2024-2030年全球及中国热障涂层(TBC)行业市场现状供需分析及市场深度研究发展前景及规划可行性分析研究报告
- 大轻质泡沫混凝土研究报告
- 室内装修工程质量保障措施方案
评论
0/150
提交评论