美文网首页
进制转换支持2~36

进制转换支持2~36

作者: wenju | 来源:发表于2022-04-02 19:10 被阅读0次
    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)
    }

相关文章

网友评论

      本文标题:进制转换支持2~36

      本文链接:https://www.haomeiwen.com/subject/xsxxsrtx.html