|
func base_convert2(number:UInt , base:UInt) -> String {
let hex : [String] = ["0" , "1" , "2" , "3" , "4" , "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V" , "W" , "X", "Y", "Z" ] var erg : String = "" var zahl : UInt = number var rest : UInt = 0; while (zahl>0) { rest = zahl % base erg = hex[ Int(rest) ] + erg zahl = zahl / base } if erg.characters.count<2 { erg = "0" + erg } return erg; }
Aufruf:
let result2:String = base_convert2(number: result1, base: system2) tOutput.text=result2
|
|