-1

我有一个十六进制值的数组,如下所示:

const UInt8 request_MifareID[] = {
        0x00, 0xCA, 0x01, 0x0A, 0x00
    };

然后我将其传输到 NSData 进行通信:

NSData *data = [[NSData alloc] initWithBytesNoCopy:(UInt8 *)request_MifareID length:5];

向服务器发送“数据”并获取服务器响应:

Printing description of resp:
<ee97562d 02280400 00000000 21074400 9000>

NSUInteger len = [resp length];

Printing description of len:
(NSUInteger) len = 18

"resp" 也是一个十六进制格式的 NSData

现在,我必须将“resp”转移到十进制数组

我应该怎么做?

-------------------------------------------------- - - 编辑

好的,首先

我必须传输服务器响应的 NSData(它不是字符串,只是数字):

ee97562d 02280400 00000000 21074400 9000

变成什么样的物体?

字节?

当我使用

NSString * str = [[NSString alloc] initWithData: resp
                                           encoding:NSUTF8StringEncoding];

它返回零

4

2 回答 2

2
int number = 0xe; // or 0x3, 0x6, 0x8, 0x2

NSString * decimalString = [NSString stringWithFormat:@"%d", number];
NSString * hexString = [NSString stringWithFormat:@"%x", number];
于 2013-10-04T10:06:29.207 回答
0
**NSData *data = [NSData dataWithBytes:"FF3C" length:4];
NSString *string = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
string = [@"0x" stringByAppendingString:string];

unsigned short value;
sscanf([string UTF8String], "%hx", &value);

NSLog(@"%d", value)**
于 2013-10-04T10:21:31.393 回答