Ian*_*lay 6 swift xcode6 swift2
我想从一个整数中获取一个两个字符的十六进制值:
let hex = String(format:"%2X", 0)
print ("hex = \(hex)")
Run Code Online (Sandbox Code Playgroud)
十六进制="0"
如何格式化String以产生总共2个字符,在这种情况下我想要
十六进制="00"
aya*_*aio 15
您可以在格式化程序字符串之前添加填充0:
let hex = String(format:"%02X", 0)
Run Code Online (Sandbox Code Playgroud)
结果:
let hex = String(format:"%02X", 0) // 00
let hex = String(format:"%02X", 15) // 0F
let hex = String(format:"%02X", 16) // 10
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3297 次 |
| 最近记录: |