Reputation: 23
I have been looking for an equivalent to JavaScripts decToBin
in Swift 2. I have not been able to find anything.
I would like to replicate the following JavaScript code code:
var max = 511;
var maxlength = decToBin(max).toString().length;
Upvotes: 0
Views: 57
Reputation: 1493
You can use String
to achieve this:
let max = 511
let maxlength = String(max, radix: 2).characters.count
You can find more in Apple String
documentation
Upvotes: 2