Beginning Swift Programming. Lee Wei-Meng

Читать онлайн.
Название Beginning Swift Programming
Автор произведения Lee Wei-Meng
Жанр Зарубежная образовательная литература
Серия
Издательство Зарубежная образовательная литература
Год выпуска 0
isbn 9781119009320



Скачать книгу

– Min: 0 Max: 18446744073709551615-println("UInt64 – Min: \(UInt64.min) Max: \(UInt64.max)")

      //-Int8 – Min: -128 Max: 127-println("Int8 – Min: \(Int8.min) Max: \(Int8.max)")

      //-Int16 – Min: -32768 Max: 32767-println("Int16 – Min: \(Int16.min) Max: \(Int16.max)")

      //-Int32 – Min: -2147483648 Max: 2147483647-println("Int32 – Min: \(Int32.min) Max: \(Int32.max)")

      //-Int64 – Min: -9223372036854775808 Max: 9223372036854775807-println("Int64 – Min: \(Int64.min) Max: \(Int64.max)")

      For each integer type, the min property returns the minimum number representable and the max property returns the maximum number representable.

      Integer Operations

      When you try to add two numbers of different integer types, you will get an error. Consider the following example:

      var i1: UInt8 = 255

      var i2: UInt16 = 255

      var i3 = i1 + i2 //-cannot add two variables

      of different types-

      To fix this, you need to typecast one of the types to be the same as the other type:

      var i3 = UInt16(i1) + i2 //-i3 is now UInt16-

      Integer Literals

      You can represent integer values as follows:

      • Decimal

      • Binary – Use the 0b prefix.

      • Octal – Use the 0o prefix.

      • Hexadecimal – Use the 0x prefix.

      The following code snippet shows the number 15 represented in the four forms:

      let num1 = 15 //-decimal-

      let num2 = 0b1111 //-binary

      let num3 = 0o17 //-octal-

      let num4 = 0xF //-hexadecimal-

      You can pad the integers with zeros if you want to make them more readable. The preceding code snippet can be rewritten as the following statements without changing the value represented:

      Конец ознакомительного фрагмента.

      Текст предоставлен ООО «ЛитРес».

      Прочитайте эту книгу целиком, купив полную легальную версию на ЛитРес.

      Безопасно оплатить книгу можно банковской картой Visa, MasterCard, Maestro, со счета мобильного телефона, с платежного терминала, в салоне МТС или Связной, через PayPal, WebMoney, Яндекс.Деньги, QIWI Кошелек, бонусными картами или другим удобным Вам способом.

/9j/4AAQSkZJRgABAQEAeAB4AAD/2wBDAAQCAwMDAgQDAwMEBAQEBQkGBQUFBQsICAYJDQsNDQ0LDAwOEBQRDg8TDwwMEhgSExUWFxcXDhEZGxkWGhQWFxb/2wBDAQQEBAUFBQoGBgoWDwwPFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhb/wAARCAHDAiYDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+