casting from smaller to larger integer

Good evening, sorry for making a whole post about something so basic but I'm honestly stumped. I just started using mojo today, past experience is a lot of rust and some c, and I can't figure out how to cast between integer types. Every type parameter I try plugging into the cast method is wrong, I couldn't find anything else that sounded right in the library docs, and kapa.ai comes up empty handed.
let small: UInt8 = 255
let big: UInt64 = # the value of small, cast to a wider size
let small: UInt8 = 255
let big: UInt64 = # the value of small, cast to a wider size
1 Reply
benny
benny7mo ago
let small: UInt8 = 255
let big: UInt64 = small.cast[DType.uint64]()
let small: UInt8 = 255
let big: UInt64 = small.cast[DType.uint64]()
DType is the actual underlying type, which can be DType.uint8, DType.uint64, etc, this is a type and NOT a value When you indicate a type in Mojo, say : UInt8, you are actually indicating that the value has the type SIMD[DType.uint8, 1], rather than DType.uint8, I hope that helps.
Want results from more Discord servers?
Add your server