Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

swift

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 number with 28 digits:

func myFunc(number : /*What to put here?*/) {
    //body
}

what type is appropriate? should number be treated as a string?

like image 518
ielyamani Avatar asked Nov 29 '22 00:11

ielyamani


1 Answers

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.

like image 96
user2864740 Avatar answered Dec 21 '22 01:12

user2864740