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
2 Replies
sora
sora•9mo ago
let val = (data[pos] << 8 | data[pos + 1]).cast[DType.uint16]()
taalhaataahir01022001
taalhaataahir01022001•9mo ago
Thank you soo much 🙂
Want results from more Discord servers?
Add your server