Search code examples
swiftfloating-pointintdecimalvar

What is the point of writing integer in hexadecimal, octal and binary?


I am well aware that one is able to assign a value to an array or constant in Swift and have those value represented in different formats.

For Integer: One can declare in the formats of decimal, binary, octal or hexadecimal.

For Float or Double: One can declare in the formats of either decimal or hexadecimal and able to make use of the exponent too.

For instance:

var decInt = 17
var binInt = 0b10001
var octInt = 0o21
var hexInt = 0x11

All of the above variables gives the same result which is 17.

But what's the catch? Why bother using those other than decimal?


Solution

  • There are some notations that can be way easier to understand for people even if the result in the end is the same. You can for example think in cases like colour notation (hexadecimal) or file permission notation (octal).