将CString转换为十六进制

编程入门 行业动态 更新时间:2024-10-22 02:42:32
本文介绍了将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 or sscanf [^] one. :)

您可以使用strtoint转换输入字符串,它接受十进制或十六进制数字,这是指向msdn帮助的链接:- msdn.microsoft/zh-cn/library/bb773451(v = VS.85).aspx?appId = Dev10IDEF1& l = EN-US& k = k(STRTOINT); k (DevLang-"C ++")& rd = true [ ^ ] :) You could convert your input string using strtoint, it accepts decimal or hex numbers, here''s a link to the msdn help:- msdn.microsoft/en-us/library/bb773451(v=VS.85).aspx?appId=Dev10IDEF1&l=EN-US&k=k(STRTOINT);k(DevLang-"C++")&rd=true[^] :)

更多推荐

将CString转换为十六进制

本文发布于:2023-10-27 15:51:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533838.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   CString   十六进制

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!