Algorithm
2022. 9. 22.
[Swift] string radix initializer
Swift radix ๊ตฌํ ๋ฐฉ๋ฒ ๋ณดํต ์๋์ ๊ฐ์ด ํจ์๋ฅผ ๊ตฌํํ๋ค. func radixTo(_ radix: Int, with number: Int) -> String { var result: String = "" var number: Int = number while number > 0 { result.append("\(number % radix)") number /= radix } return String(result.reversed()) } let number = 10 let radix2: String = radixTo(2, with: 10) // 1010 let radix3: String = radixTo(3, with: 10) // 101 ํ์ง๋ง swift๋ String์ initializer๋ก ..