将CString转换为十六进制 [英] Convert CString to hexadecimal
本文介绍了将CString转换为十六进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是MFC的新手,也不具备C ++的丰富经验.
我正在尝试将编辑框中的数据发送到串行端口.到目前为止,我可以将字符串(LPCSTR)发送到WriteFile函数.现在,我需要将用户在editbox中以十六进制格式键入的数据发送到串行端口.当我输入0X6A或$ 6A时,我想以十六进制形式发送6A作为字符串.
有人可以帮忙吗? :confused:
I am new in MFC, not much experience in C++ either.
I am trying to send data in edit box to serial port. I can send strings(LPCSTR) to WriteFile function as of now. Now I need to send data which user types in hex format in editbox to serial port. When I type say 0X6A or $6A i want to send 6A in hex otherwise as a string.
Can anybody help please. :confused:
推荐答案
6A我想以六进制形式发送6A作为字符串.
有人可以帮忙吗? :confused:
6A i want to send 6A in hex otherwise as a string.
Can anybody help please. :confused:
从十六进制表示形式(字符串)中获取一个字节几乎是一件微不足道的任务,您可以自己完成,也可以按照建议使用strtoul
[ ^ ]函数或[^ ]一.
:)
Getting a byte from its hexadecimal representation (string) is an almost trivial task, you may do it yourself or you may use, as suggested,strtoul
[^] function orsscanf
[^] one.
:)
您可以使用strtoint
转换输入字符串,它接受十进制或十六进制数字,这是指向msdn帮助的链接:-
[
You could convert your input string usingstrtoint
, it accepts decimal or hex numbers, here''s a link to the msdn help:-
http://msdn.microsoft.com/en-us/library/bb773451(v=VS.85).aspx?appId=Dev10IDEF1&l=EN-US&k=k(STRTOINT);k(DevLang-"C++")&rd=true[^]
:)
这篇关于将CString转换为十六进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文