在十六进制中转换十进制为十进制 [英] Convert hex to decimal in swift

查看:151
本文介绍了在十六进制中转换十进制为十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将十六进制转换为十进制?

我有字符串423fdf4dfb1115,我需要得到这个=> 18647576781459733。



我试试这个:

  let result = UInt8(strtoul(423fdf4dfb1115,nil,16) )

但应用崩溃...

我使用这个在线转换:
http://www.binaryhexconverter.com/十六进制到十进制转换器

解决方案

结果必须是 UInt64 UInt8.max 为255)。

有一个方便的初始化器<$ c $

  let string =423fdf4dfb1115
let result = UInt64(字符串,基数:16)


how to convert hex to decimal in swift?

I have string "423fdf4dfb1115" and I need get this => 18647576781459733.

I try this:

let result = UInt8(strtoul("423fdf4dfb1115", nil, 16)) 

but app crash...

I use this online convert: http://www.binaryhexconverter.com/hex-to-decimal-converter

解决方案

The result must be UInt64 (UInt8.max is 255).

There is a convenience initializer, strtoul is not needed.

let string = "423fdf4dfb1115"
let result = UInt64(string, radix:16)

这篇关于在十六进制中转换十进制为十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆