解決方案來源:
Swift Int 轉 16進位字串、16進位字串轉 Int
Swift native functions to have numbers as hex strings
func MyFunA() { let sStr1 = "7FFF" let nInt = strHex2Int(sStr1) print( nInt) let sStr2 = Int2strHex( nInt).uppercased() // 轉大寫 print( sStr2) } func strHex2Int(_ strHex:String) -> Int { /* 16進位字串轉Int */ let nInt = Int(strHex, radix: 16) return nInt! } func Int2strHex(_ int:Int)-> String { /* Int轉16進位字串 */ let sStr = String(int, radix: 16) return sStr }
沒有留言:
張貼留言