Convert string to bytes to data

I have a string of bytes: "0x00" and I need to convert it to a readable string which I believe should be "00". How do I do this? I've tried this:

NSUInteger length = [@"0x00" length];
NSData *sizeData = [NSData dataWithBytes: &length length: sizeof(length)];

But that isn't creating data with the actual bytes just the length. Anything I do with bytes crashes my test.
"0x00" is actually a readable string, so I do not understand what you really want to get.

Do you want to get some sort of NSData from "0x00"?

If you want to get "00" from "0x00", you just need to drop the first two characters.
Code Block
NSString *inStr = @"0x00";
NSString *outStr = [inStr substringFromIndex:2];
NSLog(@"Output: %@\n", outStr); //->Output: 00


If this is not what you want, please add more precise description. Adding more examples would help.
For example, @"0x12ab" can be a valid input? If so, what does it make?
That was the opportunity to discover Scanner.
https://stackoverflow.com/questions/41644391/convert-a-string-of-hex-to-an-int

I tested the following on playground.

Code Block
let myNumberString = "0x00"
let scanner = Scanner(string: myNumberString)
var value : UInt64 = 0
if scanner.scanHexInt64(&value) {
print("value", value)
}

Convert string to bytes to data
 
 
Q