将无符号整数转换为无符号char*
convert unsigned integer to unsigned char *
我想得到从unsigned int到unsigned char*的值,我的逻辑给出了错误的值
unsigned int Address = 0x0a5b0644; // this value is getting ss fun parameter
m_Address = (unsigned char*)Address; // this logic wrote in side C++ file
unsigned char * m_Address; // this is declared inside H file
此处m_Address未获取值0x0a5b0644
我能想出一些做的主意吗
从整数类型到指针的转换将由实现定义。
如果确实需要无符号整数类型来存储指针,请在<cstdint>
中使用uintptr_t
(或intptr_t
表示有符号整数类型)。它们在C++11中作为可选功能引入。它们能够转换为void *
类型并转换回。
您可以尝试以下操作假设无符号int是4个字节,{0x0a,0x5b,0x06,0x44}
unsigned char bytes[11];// the number of charactoer in the string + a null terminating
sprintf(bytes, "%#04x", Address); //<here it will print it
相关文章:
- 将无符号char*转换为std::istream*C++
- 如何在保持其值的同时将 c++ 无符号字符变量转换为 char 变量
- 用 Q_DECLARE_METATYPE 声明无符号的 char[]
- 覆盖性静态分析说无符号的int是char(C++)
- 错误:AES 加密密钥:从"char*"到"无符号字符"的转换无效
- 为什么 fstream.read 和 fstream.write 使用 char 而不是无符号字符?
- 通过无符号 char 别名进行对象访问,加载和存储时会发生什么?
- 将数据从 vector<unsigned char> 传输到无符号 char[]
- 如何修复此 OpenCV 错误:断言失败((无符号)i < (无符号)cn) 在 cv::Vec<unsigned char,3>:::运算符 (), 文件
- 将 const std::vector<char> 转换为无符号字符*?
- 为什么basic_fstream<无符号字符>比 Windows 上的basic_fstream慢一个数量级<char>?
- 将 C++ 转换为 Python 通过引用返回无符号 char*
- "WORD":"char [20]"与"无符号短"的间接级别不同
- 我可以在不复制的情况下将 std::vector 重新解释<char>为 std::vector<无符号字符>吗?
- 使strncmp()接受无符号的char *作为论点
- C 将char []从网络转换为主机订单,并分配给无符号int
- Vizualize无符号char *数组作为位图
- C/C++:将 char[] 转换为 int 失败,无符号 char[] 到 int 有效,为什么
- 将无符号char*缓冲区分配给字符串
- C++ 错误:对 '(std::string {aka std::basic_string}) (<char>无符号整数、字符)的调用不匹配