2. OBJECTIVE-C Programming operator

Source: Internet
Author: User
Tags bitwise operators

IOS operators are similar to other programming languages. All have arithmetic operators, assignment operators, comparison operators, logical operators, bitwise operators, and so on.

1. Arithmetic operators

Addition: +

Subtraction:-

Multiplication: *

Division:/

Remainder:%

Self-add: + +

Self-reduction:--

There are some other:

+=

-=

*=

/=

%=

&=

|=

^=

<<=

>>=

These are very simple, some places but also pay attention to

★ The two operators of division are integer types, then it evaluates to integer type, that is, intercept rounding.

The ★+ number can also be used as a connector.

★ Special note that self-add & decrement is the monocular operator, that is, there is only one number to do the operation. When you add/subtract, ++/--on the left side of the operand, first put the arithmetic plus/minus 1;++/--on the right of the operand, and then add/subtract 1 after the operand is calculated.

★ If you need to add some more complex operations, then you can import #include <math.h> header file, which contains a lot of computing methods.


2. Assignment operators

is a "=" number, assigning the right value to the left.


3, bitwise operators

1) &: Bitwise AND

2) |: Bitwise OR

3) ~: Bitwise non-

4) ^: Bitwise XOR

5) <<: Left shift operator

6) >>: Right shift operator


Popularize knowledge: (This is a very fucked-up thing, but be sure to understand) all the numbers are in binary form at the bottom of the computer, that is, there are only 0 and 1 of these two things. The original code refers to a current value converted into binary form. But the computer is not the original code, but the complement. The complement is like this, two cases: if positive, it is the same as the original code, if negative, its complement is anti-code plus 1 (TMD is dead) anti-code is the original code to take the reverse, the highest bit unchanged, the most high is the sign bit. Did you see that?


Left shift operator: The binary code that converts the operand to the left direction moves the specified number of digits, and the right empty place is filled with 0. Moving right is the opposite of moving left.

In fact, the displacement operation can also be used in this way, when the left shift n is the equivalent of multiplying by 2 n times, the right shift is divided by 2 of the n-th square.


4. Comparison operators

: Greater Than

<: Less than

>=: greater than or equal to

<=: Less than or equal to

= =: equals

! =: Not equal to


5. Logical operators

&&: With--two must be true to return true.

|| : Or--a true return is true.

!: Non--true return False, False return true.

^: XOR-Two different returns True, same return false.


6, trinocular operator

Conditions? Expression 1: Expression 2

Equivalent to If...else ... Judge


Chapter Two, End!

This article is original, reproduced please specify the source, prohibited for commercial use. Thank you!

http://blog.csdn.net/zsfz_053/article/details/42236687

2. OBJECTIVE-C Programming operator

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.