Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
尽管您的问题缺乏一些信息,但我试图为我所理解的内容提供答案。
#include <stdio.h> #include <stdint.h> #define NUM_VALUES 5 int main(void) { uint8_t input_data[NUM_VALUES * 2] = {1, 2, 0x0d, 0x60, 5, 6, 7, 8, 9, 10}; uint16_t result_data[NUM_VALUES]; for (int i = 0; i < NUM_VALUES; i++) { result_data[i] = (uint16_t)input_data[2*i] << 8 | input_data[2*i+1]; printf("result[%d] = 0x%04x == %5u\n", i, result_data[i], result_data[i]); } }
输出:
~/tests$ ./test result[0] = 0x0102 == 258 result[1] = 0x0d60 == 3424 result[2] = 0x0506 == 1286 result[3] = 0x0708 == 1800 result[4] = 0x090a == 2314
如您所见,十六进制和十进制仅表示相同的值。
While your question lacks some information, I try to provide an answer for what I have understood.
Output:
As you can see, hex and decimal are only representation of the same value.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(1)
尽管您的问题缺乏一些信息,但我试图为我所理解的内容提供答案。
输出:
如您所见,十六进制和十进制仅表示相同的值。
While your question lacks some information, I try to provide an answer for what I have understood.
Output:
As you can see, hex and decimal are only representation of the same value.