Is there a number type with bigger capacity than u_long/UInt64 in Swift?

后端 未结 4 483
鱼传尺愫
鱼传尺愫 2021-01-19 06:21

Is there a type with bigger capacity than u_long or UInt64 in Swift?

I have a function that takes very big integers to identify a credit card numbe

4条回答
  •  余生分开走
    2021-01-19 07:00

    A credit card number is not a number in a meaningful mathematical sense. It is a sequence of digits and a CC should be treated as text, much like a phone number. One immediate issue of using a fixed-length integer value is that code cannot simultaneously detect leading and trailing zeros from "no more numbers present".

    Use a string or a specific (custom) type representing the CC number, probably using a string internally. The length of the number (in base-10) is then trivially the number of digits: which is the length of the underlying string.

    The CC number (represented by a bonafide string) can later be encoded into an appropriate binary representation, if (and when) required.

提交回复
热议问题