C++ 实现string转BYTE
用于将形如"0x1A"的string转成BYTE类型
代码如下, 有问题欢迎指出
bool str2byte(const std::string &str, BYTE &bRet)
{
bRet = 0x00; //结果
size_t iPos = ; //位
size_t power = ; //幂次 //没找的'x'返回
if(std::string::npos == str.find("x"))
{
return false;
} //从右往左依次取每个字符
while (str.find("x") != (str.length()-iPos))
{
char cVal = str[str.length()-iPos];
int iVal = int(cVal); //0~9
if ((iVal >= ) && (iVal <= ))
{
bRet += ((iVal-) * power);
}
//A~F
else if ((iVal >= ) && (iVal <= ))
{
bRet += ((iVal-) * power);
}
//a~f
else if ((iVal >= ) && (iVal <= ))
{
bRet += ((iVal-) * power);
} ++iPos;
power *= ;
} return true;
}
C++ 实现string转BYTE的更多相关文章
- string转byte[]
static byte[] GetBytes(string str) { byte[] bytes = new byte[str.Length * sizeof(char)]; System.Buff ...
- java String与Byte[]和String 与InputStream转换时注意编码问题。。。
前一段日子,我在做rsa加密和通过http get方式获取验证码图片通过BitmapFactory创建bitmap 出现了一系列的问题. 通过一系列的调试,发现有些问题原来是在进行String 与By ...
- java中string与byte[]的转换
1.string 转 byte[] byte[] midbytes=isoString.getBytes("UTF8"); //为UTF8编码 byte[] isoret = sr ...
- C# double float int string 与 byte数组 相互转化
在做通信编程的时候,数据发送多采用串行发送方法,实际处理的时候多是以字节为单位进行处理的.在C/C++中 多字节变量与Byte进行转化时候比较方便 采用UNION即可废话少说看示例:typedef u ...
- java Byte.toString 方法与String.ValueOf(Byte)效率比较
int times = 10000000; Byte[] li = new Byte[times]; for (int i = 0; i < times; i++) { li[i] = (byt ...
- C# String 与 byte 互转
String转换为byte数组用byte[] arr = System.Text.Encoding.Default.GetBytes("abcde") byte数组转换为Strin ...
- string和byte[]的转换 (C#)
原文 string和byte[]的转换 (C#) string类型转成byte[]: byte[] byteArray = System.Text.Encoding.Default.GetBytes ...
- C#中string和byte[]相互转换问题解决
本来想讲string转换为byte数组,通过在VS上打 ‘str. “来找,结果半天没发现跳出来的函数中有想要的,哭瞎 /(ㄒoㄒ)/~~ 这回将两种情况都记下来了.... string ---> ...
- Go中string转[]byte的陷阱
Go中string转[]byte的陷阱html {overflow-x: initial !important;}#write, body { height: auto; }#write, #writ ...
- golang string和[]byte的对比
golang string和[]byte的对比 为啥string和[]byte类型转换需要一定的代价?为啥内置函数copy会有一种特殊情况copy(dst []byte, src string) in ...
随机推荐
- 个人第四次作业--Alpha项目测试
这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience 这个作业要求在哪里 https://www.cn ...
- zerotier 远程办公方案
武汉新肺炎疫情下,搞得人心惶惶.很多公司都要求前期远程办公 我厂日常有在家远程应急支持的情况,所以公司很早就有VPN服务.只需要申请VPN服务,开通之后就可以连上公司各种公共资源. 然而对于一些非公共 ...
- 网络流(最大流-Dinic算法)
摘自https://www.cnblogs.com/SYCstudio/p/7260613.html 网络流定义 在图论中,网络流(Network flow)是指在一个每条边都有容量(Capacity ...
- 详细步骤:手动添加bits/stdc++.h到vs2017
本机环境:win10系统 64位 vs2017 最近码代码时偶然发现了bits/stdc++.h这个头文件(万能头文件),基本上所有的代码只要用了这个头文件就不再写其他头文件了. 看到它就仿佛开启了新 ...
- Leetcode 题目整理-6 Swap Nodes in Pairs & Remove Duplicates from Sorted Array
24. Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For ...
- 使用c++标准IO库实现txt文本文件的读与写操作
练习c++primer中关于输入输出流的操作. 任务是从固定格式的forreading.txt文档中读取相应的数据,转存到forwriting.txt中去. forreading.txt 格式如下: ...
- 找不到文件异常java.io.IOException: Resource [classpath:shiro.ini] could not be found.
情景 tomcat启东时,老是报错,在classpath下找不到配置文件,但是配置文件已经放在resource目录下了 解决方案 出现该异常的原因,是因为新建的conf文件夹,识别不了,因为没有设置成 ...
- Intent传递实现Parcelable接口的对象
Intent可以传递基本数据类型,在对象实现了Parcelable接口后,Intent也可以传递对象. 1. 使类ListVideo实现了Parcelable接口. package com.examp ...
- Win10系统下如何将中文登录名改为英文登录名
需求:本人每次在换完系统后是默认,图方便,登录名就直接是自己的名字,造成以后安装个别软件时会莫名其妙的出错. 解决办法: 1.在当前用户开始处-点击右键(Windows键+X)-注销 2.切换到Adm ...
- centos7安装OTRS6
1.在文件/etc/selinux/config中配置SELINUX=disabled 重启系统.重启后确认命令getenforce返回为Disabled 2.配置数据库 我们这里使用MariaDB ...