Hexadecimal To Binary


More Conversions



Example Code

NSString *binaryString = @"1111";
/* Binary to Dec*/
NSLog(@"Decimal Value for binary String is %ld", strtol([binaryString UTF8String], NULL, 2));

/* Binary to Hex*/
NSLog(@"Hexadecimal Value for Binary String is %2lX", (unsigned long)strtol([binaryString UTF8String], NULL, 2));

/* Binary to Octal*/
NSLog(@"Octal Value for Binary String is %2lO", (unsigned long)strtol([binaryString UTF8String], NULL, 2));
var binaryString = "1111"

/* Binary to Decimal*/
var decimalString = String(Int(binaryString, radix: 2)!, radix: 10)
print("Decimal Value for Binary String \(binaryString) is ", decimalString);

/* Binary to Hex*/
var hexString = String(Int(binaryString, radix: 2)!, radix: 16)
print("Hexadecimal Value for Binary String \(binaryString) is ", hexString);

/* Binary to Octal*/
var octalString = String(Int(binaryString, radix: 2)!, radix: 8)
print("Octal Value for Binary String \(binaryString) is ", octalString);

Result

Decimal Value for Octal String is 15
Hexadecimal Value for Octal String is  F
Binary Value for Octal String is 1111

Advertisements