Swift's numeric literal constants

Source: Internet
Author: User

Different binary integer values are differentiated by the following principles:

1. No prefix in decimal number

2. One binary number, plus a 0b prefix

3. An octal number, plus a 0o prefix

4. A 16 binary number, plus a 0x prefix

Below is a different representation of the integer value of 17 in the form of a binary:

Let Decimalinteger = 17

Let Binaryinteger = binary representation of 0b10001//17

Let Octalinteger = octal representation of 0O21//17

Let Hexadecimalinteger = hexadecimal representation of 0x11//17

Floating-point numbers can be either decimal or 16 binary. Floating-point numbers have at least one number (or hexadecimal number) on either side of the decimal point. Floating-point numbers can also have an optional exponent that can be used to denote a decimal floating-point number in either a uppercase or lowercase e, or a hexadecimal floating-point number with a size or lowercase p.

You can add an exp index to a decimal number and multiply the cardinality by 10exp:

1.25e2 means 1.25x102, or 125.0
1.25e-2 means 1.25x10-2, or 0.0125

can be a hexadecimal plus an exp index, the radix multiplied by 2exp

0XFP2 means 15x22, or 60.0.
0xfp-2 means 15x2-2, or 3.75.

Here are the various representations of a floating-point number:

Let?? decimaldouble? =? 12.1875

Let? exponentdouble? =? 1.21875e1

? Let?? hexadecimaldouble? =? 0xc.3p0

Numeric literals can also contain extended formats to make the literal more readable, and integers and decimals to be filled with some additional 0 can also contain underscores to help with the readability of the literal. The type of the format does not affect the value of the literal itself.

Let paddeddouble = 000123.456//123.456

Let onemillion = 1_000_000//1000000

Let justoveronemillion = 1_000_000.000_000_1//1000000.0000001

Swift's numeric literal constants

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.