-5

As far I searched there is no API to convert hexadecimal to decimal or binary

Is there any workarounds ?

NaveenKumar
  • 600
  • 1
  • 5
  • 18

1 Answers1

1

Following are methods to convert into binary and hexadecimal ( If you are expecting string from integer value.)

1) To convert into binary

- (NSString *)binaryStringWithInteger:(NSInteger)value
{
    NSMutableString *string = [NSMutableString string];
    while (value)
   {
    [string insertString:(value & 1)? @"1": @"0" atIndex:0];
    value /= 2;
   }
   return string;
}

2) To convert into hexadecimal

Hexadecimal is just a way of displaying an integer.

if you want to create a string that is the hexadecimal representation of an integer, you can use this code:

- (NSString *)hexFromInt:(NSInteger)val
{
return [NSString stringWithFormat:@"0x%X", val];
}
Shrikant K
  • 1,988
  • 2
  • 23
  • 34