0

I have a value in my user defaults .plist

<key>hex</key>
<data>5448495344414e475448494e474e45454453544f53544159484558</data>

How would i put that into a char [] like this:

char hex[] = {0x54,0x48,etc..}

I searched around and haven't found any examples. I have tried everything I can think of.

enum {
   NSBinarySearchingFirstEqual = (1 << 8),
   NSBinarySearchingLastEqual = (1 << 9),
   NSBinarySearchingInsertionIndex = (1 << 10),
};
typedef NSUInteger NSBinarySearchingOptions;

NSString *str = @"string";
const char *myChar = "some string";
if (strcmp(myChar,  str.UTF8String))

or

[str isEqualToString:[NSString stringWithUTF8String:myChar]];

CFStringRef myStr = CFSTR("some chars");

bool result = CFStringCompareWithOptions(myStr, ((__bridge CFStringRef)str),CFRangeMake(0,CFStringGetLength(myStr)), kCFCompareCaseInsensitive);

    int someInteger = 42;

    float someFloatingPointNumber = 3.1415;

    double someDoublePrecisionFloatingPointNumber = 6.02214199e23;


    int someInteger = 42;

    someInteger++;            // someInteger == 43



    int anotherInteger = 64;

    anotherInteger--;         // anotherInteger == 63



    anotherInteger *= 2;      // anotherInteger == 126

If you use a scalar type for an Objective-C property, like this:

@interface XYZCalculator : NSObject

@property double currentValue;

@end


@implementation XYZCalculator

- (void)increment {

    self.currentValue++;

}

- (void)decrement {

    self.currentValue--;

}

- (void)multiplyBy:(double)factor {

    self.currentValue *= factor;

}

@end

short myint;
long myint;
unsigned myint;
signed myint;

I asked a similar question, but not this specifically.

OGHaza
  • 4,795
  • 7
  • 23
  • 29
ctfd
  • 338
  • 3
  • 14
  • 2
    `NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"hex"]; const char *hex = data.bytes;` –  Feb 01 '14 at 18:21
  • 1
    Where is the difference to your previous question http://stackoverflow.com/questions/21481945/nsstring-to-nsdata-conversion-to-hex-value ? – Martin R Feb 01 '14 at 18:24
  • @martinr, i didn't ask the right question really. it was too vague according the comments and didn't say this exactly, about need to take the data and put it into a char [] – ctfd Feb 01 '14 at 18:26
  • @H2CO3, i think that does work, so you put as an answer, thank you. – ctfd Feb 01 '14 at 18:36
  • From my answer to the previous version of the question: "If you want access to the bytes in an NSData just access them directly: theData.bytes`." – zaph Feb 02 '14 at 00:57
  • @Zaph, hi - it wasn't clear to me that is what you were stating, since it was a bit vague. the example H2C03 posted was the key to helping me understand how to actually use it. if you want to update your answer using the example i'll gladly mark it as correct. – ctfd Feb 02 '14 at 07:37
  • No need, this can be a difficult thing to understand. It was easier years ago when we routinely saw the underlying bits. – zaph Feb 02 '14 at 16:01
  • @Zaph, I hope they would bring the underlying bits back, since the multifarious ones seem to agglutinate within my functions, leaving me with hives. At the very least they should make them available in punchcard and/or microfiche format. – ctfd Feb 03 '14 at 20:43

0 Answers0