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?
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.
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