I can 100% guaranty the value of input int variable is always unsign(positive) and less than int16.
How can I convert this int type variable to uint16?
// convert the type and assign to new variable or pass as a parameter.
var i int
...
u := uint16(i)
foo(uint16(i))
You need to check that the number is not negative and that it is <= 0xFFFF and then cast it to an unsigned 16 bit int.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With