# Swift Program to convert Hexadecimal to Decimal

This tutorial will discuss how to write Swift program to convert Hexadecimal to Decimal.

Decimal numbers are those numbers whose base value is 10. Decimal numbers are also known as base-10 number system which contain 10 numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Here, the position of every digit in the decimal number has weight is a power of 10.

Hexadecimal numbers are those numbers whose base value is 16. Hexadecimal numbers are also known as base-16 number system which contain 16 symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F. Here, A, B, C, D, E, and F also represents decimal numbers 10, 11, 12, 13, 14, 15. Here, the position of every digit in the hexadecimal number has weight is a power of 16. For example, 2A3 is a hexadecimal number.

Hexadecimal to Decimal conversion table −

0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
A 10
B 11
C 12
D 13
E 14

Below is a demonstration of the same −

Input

Suppose our given input is −

Output

The desired output would be −

Decimal number = 45

To convert the hexadecimal(base-16) into decimal number(base-10) we use Int(_:radix:). This method create a new value from the given string/number and radix.

### Syntax

Following is the syntax −

Here, value is the ASCII representation of a number. Whereas radix is used to convert text into integer value. The default value of radix is 10 and it can be in the range from 2…36.

### Example

The following program shows how to convert Hexadecimal to decimal number.

import Foundation
import Glibc

let hexaNumber = "3C5"

// Converting hexadecimal number into decimal number
let deciNumber = Int(hexaNumber, radix: 16)!
print("Decimal Number:", deciNumber)