本文介绍了如何将uint16数组转换为uint8数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将具有5个元素的uint16数组转换为uint8数组
[edit]
从OP注释到解决方案之一(更详尽的解释):
感谢答谢,但我想将uint16的两个字节分开,然后我将得到的总共10个字节应该放在uint8的数组中"
[/edit]
to convert array of uint16 having 5 elements to array of uint8
[edit]
From OP in comment to one of the solutions (explains more thoroughly):
"thanx for replying but i want to separate both bytes of uint16 and then the total 10 bytes which , i will get should be in array of uint8"
[/edit]
推荐答案
uint16 arr1[5] = {2, 3, 20, 90, 3857};
uint8 arr2[10] = {0};
uint8* ptr = (uint8 *) &arr1; //cast the 16bit pointer to an 8bit pointer
for(int i=0; i<10; i++)
{
arr2[i] = *ptr; //pass data to other array
ptr++; //move your pointer
}
for(int i = 0; i < 10; i++)
{
cout << ptr[i] << endl;
}
最好的问候
Espen Harlinn
Best regards
Espen Harlinn
这篇关于如何将uint16数组转换为uint8数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!