ModularM
Modular3y ago
2 replies
taalhaataahir01022001

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
image.png
Was this page helpful?