Chapter 10 : Binary, Octal, Hexadecimal Numbers

Topics Covered :

1. Decimal Numbers
2. Binary Numbers
3. Octal Numbers
5. Examples

# Binary, Octal, Hexadecimal Numbers

### Decimal Numbers

By default all number defined are Decimal (to the base 10).

Example : 10, -120.30, 0 , 110393 , 4/3

### Binary Numbers

Binary numbers have a base 2.To denote a number as a binary Number it has to be prefixed with 0b

Example : 0b1010, 0b10, 0b10101

### Octal Numbers

Octal numbers have a base 8.To denote a number as a Octal Number it has to be prefixed with 0o

Example : 0o127, 0o1234

Hexadecimal numbers have a base 16.To denote a number as a Hexadecimal Number it has to be prefixed with 0x

Example : 0x12A, 0oFC4

``````
//
//  main.swift
//  Swift Tutorials 2014-15
//  Boolean in Swift
//
//  Created by Code2care on 15/09/14.
//

var myDecimal  = 20;
var myBinaryNumber = 0b101010;
var myOctalNumber = 0o17;
var myHexaDecimalNumber = 0xFFA;

//Note that the output will be converted to decimal numbers
println("\(myDecimal)")
println("\(myBinaryNumber)")
println("\(myOctalNumber)")