C++小字符到十六进制函数
C++ Small char to hex function?
我正试图找到一种非常轻量级的方法,通过下面的两个例子来实现对char或md5的十六进制运算。
char example[0x34];
char example_final[0x200];
sprintf(example, "%s", "4E964DCA5996E48827F62A4B7CCDF045");
下面是使用两个PHP函数的示例。
MD5:
sprintf(example_final, "%s", md5(example));
output: 149999b5b26e1fdeeb059dbe0b36c3cb
十六进制:
sprintf(example_final, "%s", bin2hex(example));
output: 3445393634444341353939364534383832374636324134423743434446303435
这是最轻量级的方法。我想用一些大的char数组来表示它的十六进制值,而不是用foreach char做一个循环,但不确定。
bin2hex
的示例如下:
#include <string>
#include <iostream>
std::string bin2hex(const std::string& input)
{
std::string res;
const char hex[] = "0123456789ABCDEF";
for(auto sc : input)
{
unsigned char c = static_cast<unsigned char>(sc);
res += hex[c >> 4];
res += hex[c & 0xf];
}
return res;
}
int main()
{
std::string example = "A string";
std::cout << "bin2hex of " << example << " gives " << bin2hex(example) << std::endl;
}
相关文章:
- 如何在openssl-ecc中获取十六进制格式的私钥
- 如何将包含epoch时间的十六进制字符串转换为time_t
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- 如何将一个ostringstream十六进制字符串字符对转换为单个unit8t等价的二进制值
- 在setiosflags函数中使用十六进制标志
- C++ 在地板函数之后以十六进制打印数字
- 是否有函数或公式可以在 c++ 中将字符串"of letters"转换为十六进制
- 按位函数 AND、OR 和 XOR 在 C++ 中使用十六进制字符串
- 将十六进制数作为主要函数参数
- 从十六进制值返回 OpenGL #define 错误名称的函数
- 十进制到十六进制转换c++内置函数
- 为什么我的 RGB 转十六进制函数在传递颜色分量时返回 0
- 为什么该函数以相反的顺序显示十六进制代码
- GDB:显示函数将我的 {type} 的地址打印为整数——想改成十六进制
- C++小字符到十六进制函数
- C++/CLI中的十进制到十六进制函数
- C++:十六进制到十进制的转换函数-没有得到正确的输出
- 我需要写一个函数,将十六进制转换为十进制,并使用递归,我不断得到运行时错误
- C++:STRING函数返回十六进制值而不是字符串
- 将常量转换为十六进制字符串的C/ c++宏函数