convert UInt8 to UInt16
Assuming this code in C
uint16_t get2i(uint8_t const * const data, uint_fast32_t * const pos)
{
uint16_t val=(data[pos]<<8)|data[(pos)+1];
(*pos)+=2;
return val;
}
What data is 8 bit unsigned interger i.e.,
uint8_t * data;
But how can I write this code in mojo. I'm trying to write this:
fn get2i(data: DynamicVector[UInt8],inout pos: Int) -> UInt16:
let val:UInt16 = (data[pos] << 8) | data[pos + 1]
pos += 2
return val
But it gives me the following error:
annot implicitly convert 'SIMD[ui8, 1]' value to 'SIMD[ui16, 1]' in 'let' initializer
![No description](https://cdn.answeroverflow.com/1193288136424427642/image.png)
2 Replies
let val = (data[pos] << 8 | data[pos + 1]).cast[DType.uint16]()
Thank you soo much 🙂