---
title: "Objective-C把十六进制格式字符串转成数字"
author: "swordinhand"
date: "2013-11-21T16:50:39Z"
tags: []
categories: ["编程语言"]
slug: "objective-c"
draft: false
lastmod: "2013-11-21T16:50:39Z"
id: 1978544
url: "https://swordinhand.iteye.com/blog/1978544"
---

```Objective-C

unsigned int outVal;
NSScanner* scanner = [nsscanner scannerwithstring:@"9ef"];
[scanner scanhexint:&outval];
NSLog(@"%d", outVal);

```


上面的代码会输出2543

@"9EF"也可以是@"0x9EF"，十六进制数字的大小写都可以。