20
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Swift 3 で16進数文字列と整数の相互変換

Last updated at Posted at 2017-08-09

整数 → 16進数文字列

String(42, radix: 16) // => "2a"

16進数文字列 → 整数

Int("2a", radix: 16)! // => 42

入力が数値にパースできない文字列の場合は nil になる。

Int はプラットフォームのネイティヴなビット幅と同じ幅を持つ(64ビットプラットフォームなら Int64 と同じ)。他のビット数や符号なしなどの型にしたいなら UInt8 などと指定すればOK。

20
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?