Int to UInt (and vice versa) bit casting in Swift

前端 未结 3 675
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 01:39

I am looking for a direct way to bit cast the bit values of an Int to UInt and vice versa. For example (using the 8 bits integers for simplicity) I want to achieve the follo

3条回答
  •  误落风尘
    2020-12-14 02:36

    numericCast(...) is what you're looking for. It's a set of generic functions that converts from and to different number types. It picks the correct implementation based on the types of its argument and the return type.

提交回复
热议问题