相关疑难解决方法(0)

在Swift中将十六进制字符串转换为NSData

我得到了在Objective-C中将String转换为HEX-String的代码.

- (NSString *) CreateDataWithHexString:(NSString*)inputString
{
NSUInteger inLength = [inputString length];


unichar *inCharacters = alloca(sizeof(unichar) * inLength);
[inputString getCharacters:inCharacters range:NSMakeRange(0, inLength)];

UInt8 *outBytes = malloc(sizeof(UInt8) * ((inLength / 2) + 1));

NSInteger i, o = 0;
UInt8 outByte = 0;

for (i = 0; i < inLength; i++) {
    UInt8 c = inCharacters[i];
    SInt8 value = -1;

    if      (c >= '0' && c <= '9') value =      (c - '0');
    else if (c >= 'A' && c <= 'F') value …
Run Code Online (Sandbox Code Playgroud)

objective-c ios swift

32
推荐指数
5
解决办法
3万
查看次数

标签 统计

ios ×1

objective-c ×1

swift ×1