Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>uint8_t one = 0xBA; uint8_t two = 0xBE; uint16_t both = one &lt;&lt; 8 | two; </code></pre> <p><strong>UPDATE:</strong> Maybe I have not understood your problem... but if you want to convert a uint8_t array to a uint16_t array-> check size and cast</p> <pre><code>uint8_t array[100]; uint16_t array_ptr_ushort* =(uint16_t*)&amp;array[0]; </code></pre> <p>Make sure the size of the array is even.</p> <p><strong>UPDATE2:</strong></p> <pre><code>uint8_t array1[100]; uint8_t array2[100]; uint16_t combined[100]; memcpy(combined, array1, sizeof(array1)) memcpy((uint8_t*)combined + sizeof(array1), array2, sizeof(array2)) </code></pre> <p><strong>UPDATE3:</strong></p> <p>You can not combine two arrays in one contignous array without some sort of loop, the loop will exist in the underlying hardware even you use DMA for this...</p> <p><strong>UPDATE4:</strong></p> <p>You can do it recursively.</p> <pre><code>#include "stdafx.h" #include &lt;cstdint&gt; #include &lt;algorithm&gt; uint8_t arrayA[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; uint8_t arrayB[] = {0xA, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1}; uint16_t array_combined[sizeof(arrayA)] = {}; static_assert(sizeof(arrayA) == sizeof(arrayB), "Arrays of different sizes"); uint16_t combine(const uint8_t *a, const uint8_t *b, uint16_t *put, uint32_t size) { uint16_t value = (*a &lt;&lt; 8) | *b; if(size) *put = combine(++a, ++b, ++put, --size); return value; } void combine_arrays(const uint8_t *a, const uint8_t *b, uint16_t *put, uint32_t size) { *put = combine(a, b, put, size); } int _tmain(int argc, _TCHAR* argv[]) { combine_arrays(arrayA, arrayB, array_combined, sizeof(arrayA)); return 0; } </code></pre> <p><strong>UPDATE5:</strong> C version with static_assert from C++</p> <pre><code>#include &lt;stdint.h&gt; uint8_t array1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; uint8_t array2[] = {0xA, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1}; uint16_t array_combined[sizeof(array1)] = {}; static_assert(sizeof(array1) == sizeof(array2), "Arrays of different sizes"); int _tmain(int argc, _TCHAR* argv[]) { int size = sizeof(array1); int count = 0; do { array_combined[count] = (array2[count] &lt;&lt; 8) | array1[count]; }while(count++ != size); return 0; } </code></pre> <p><strong>UPDATE6:</strong> There are also C++ ways to achieve this...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload