进制转换支持2~36

2022-04-02  本文已影响0人  wenju
    func transition(fromBase:Int, toBase:Int, beforeNum:String) throws -> String{
        if((fromBase<2 || 36<fromBase || toBase<2 || 36<toBase)){
            throw NSError(domain: "bigNum", code: -1, userInfo: nil)
        }else if(Int(beforeNum, radix: fromBase) == nil){
            throw NSError(domain: "bigNum", code: -1, userInfo: nil)
        }else if(beforeNum.isEmpty){
            throw NSError(domain: "bigNum", code: -1, userInfo: nil)
        }
        
        return String(Int(beforeNum, radix: fromBase)!, radix:toBase)
    }
上一篇 下一篇

猜你喜欢

热点阅读