Get the App
SLTechnology News&Howtos  ›  Development  › 

How to learn iOS median operation .md through Objective-C enumeration

Shulou Source: shulou.com Published: 2022-06-03 09:48:14 11月15日 Update

This article is about how to learn about the iOS middle operation .md through the enumeration of Objective-C. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Bit operation

A bit operation is to operate or shift a binary number bit by bit. It consists of two operations: bit operation and shift. Let's learn more about these two operations.

Only the operators for all bit operations in iOS are discussed here. Operators with the same meaning in other languages may be different.

Bit operator (the following operators are all the same as Objective-C)

A type of bit operator includes the following:

~ (reverse, unary operator): it inverts each binary of the target number

Let initialBits: UInt8 = 0b00001111let invertedBits = ~ initialBits / / equals 11110000

| | (bitwise OR): it operates on the same position of two target digits. Rules: 0 and 0 are 0, 0 is 0, 1 is 1, and 1 is 1. 1 is 1. |

Let targetNum = 5 / / 101let targetNum2 = 6 / / 110print (targetNum | targetNum2) / / print 7//targetNum: 101//targetNum2: 110//result: 111 (decimal 7)

& (bitwise and): it operates on the same position of two target digits. The rules are: 0 and 0 for 0 and 1 for 1

Let targetNum = 5 / / 101let targetNum2 = 6 / / 110print (targetNum & targetNum2) / / print 4//targetNum: 101//targetNum2: 110//result: 100 (decimal 4)

^ (XOR): it performs XOR on the same position of the two target digits, and if different, the bit is 1, otherwise the bit is 0. Rules: if 0 and 0 are 0, 0 is 0, 0 is 1, 1 is 1, and 1 is 0.

Let targetNum = 5 / / 101let targetNum2 = 6 / / 110print (targetNum ^ targetNum2) / / print 3//targetNum: 101//targetNum2: 110//result: 011 (decimal 3)

Shift

> > (move to the right): it moves the target number to the right x bit by bit

Let targetNum = 5 / / 101print (targetNum > > 2) / / print 1//targetNum: 101 stroke / move 2 bits to the right / / result: 1 (decimal 1)

Tags: Operations numbers decimal decimal goals same two positions attributes operators rules operators learning different binary content multiple cases more article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Tech Info macOS Linux OPPO Reno