正在将char转换为无符号整数
Converting char to unsigned integer
我将一个巨大的二进制文件读取到char
s的向量中。
我需要将每个字节视为一个无符号整数(从0到255);并做一些算术运算。如何将矢量转换为矢量?
char a = 227;
cout << a;
打印?
char a = 227;
int b = (int) a;
cout << b << endl;
打印-29
char a = 227;
unsigned int b = (unsigned int) a;
cout << b << endl;
打印4294967267
char a = 227;
unsigned char b = (unsigned char) a;
cout << b << endl;
打印?
std::vector<char> source;
// ... read values into source ...
// Make a copy of source with the chars converted to unsigned chars.
std::vector<unsigned char> destination;
for (const auto s : source) {
destination.push_back(static_cast<unsigned char>(s))
}
// Examine the values in the new vector. We cast them to int to get
// the output stream to format it as a number rather than a character.
for (const auto d : destination) {
std::cout << static_cast<int>(d) << std::endl;
}
相关文章:
- 从 std::string 转换为 const 无符号整数
- 在C++中,将无符号整数转换为八进制表示,反之亦然的最佳方法是什么
- 将二进制编码的无符号字符转换为整数
- 如何将以"\0"开头的字符 * 转换为无符号整数?
- 为什么C++标准指定有符号整数在具有混合符号的二进制操作中强制转换为无符号整数
- g++ 在不使用 -Wconvert 的情况下将 double/float 转换为无符号整数时发出警告
- 有符号整数和无符号整数之间的转换
- 将负整数强制转换为更大的无符号整数
- 在Python中获取从有符号整数到无符号整数的转换
- 从双精度到无符号整数的转换
- 正在尝试读取4字节无符号整数的二进制文件并转换为伏特
- 如果我有一个固定大小的填充ascii数字的char数组,我知道它指的是一个无符号整数,那么将其转换为无符号整数的最快方法
- 将浮点数 32 位变量类型转换为无符号整数 32 位时进行了哪些位级更改
- 如果使用无符号整数,则通过减去1将基于1的编号转换为基于0的编号是否安全
- 将字节转换为无符号整数的最快方法
- 将浮点转换为无符号整数c++
- 将4个字节按小端序转换为无符号整数
- 正在将char转换为无符号整数
- 将无符号整数转换为无符号char*
- 将MFC CString转换为无符号整数