From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Why use uint8?

Why use uint8?

- [Instructor] While you usually use an integer for counting, indexing, and some math, there's also its pure binary form, the unsigned integer. Let's look at what you can do with an unsigned integer. Open up a blank Swift playground. And call it UnsignedInteger. And get rid of what was there already, 'cause we won't need it. So, declare a variable as an unsigned integer eight with value one, and you do that by going var a:UInt8 = 1. This is an 8-bit binary number. By getting rid of the sign and making everything positive, you access all the bits for data manipulation. It translates in binary as 0000 0001. And since those are so hard to write out, we tend to use hexadecimal numbers instead, and this translates easily into the hexadecimal number 01, which is easier to use for unsigned integers. If you're not familiar with hex numbers, they're base 16 numbers, one digit equals four binary bits. This makes them a great shorthand for long binary numbers. The number is the decimal…

Contents