提交工单
咨询集成、功能及报价等问题
All numbers in the program are stored in binary form in the computer memory, and bit operations are directly operated on the binary bits of the integer in the memory.
Symbols | Meaning | Operation Rules | Examples |
---|---|---|---|
& | And | When both bits are 1, the result is 1. | 0&1=0, 1&1=1. |
| | Or | When both bits are 0, the result is 0. | 0 |
^ | XOR | If two bits are the same, it is 0, and if they are different, it is 11. | 1^1=0, 0^1=1. |
~ | Inverted | 0 becomes 1, and 1 becomes 0. | ~1=0, ~0=1. |
<< | Shift left | Shift all the numbers to the left by the corresponding number of digits in binary form, shift out the high position (discard), and fill in the low vacancy with zero. | For example, the binary of the integer 3 is 00000011, and 3 << 2 means that the binary bit of the number 3 is shifted to the left by 2 bits, and the binary bit after the shift is 00001100. |
>> | Signed right shift | According to the binary form, move all the numbers to the right by the corresponding number of bits, shift out (discard) the low, and fill the sign bit with the high space, that is, add zero for positive numbers and add 1 for negative numbers. | For example, the binary of the integer 3 is 00000011, and 3 >> 1 means that the binary bit of the number 3 is signed to the right by 1 bit, and the shifted binary is 00000001. |
>>> | Unsigned right shift | Shift all the numbers to the right by the corresponding number of bits in binary form, shift out (discard) the low bits, and fill in zeros in the high vacancies. For positive numbers, the rules are the same as for signed right shifting, but for negative numbers it is different. | For example, the binary of the integer 3 is 00000011, and 3 >> 1 means that the binary bit of the number 3 is signed to the right by 1 bit, and the shifted binary is 00000001. |
The SDK mainly uses the bitmask principle to implement multiple switch operations, that is, when multiple selections of module switches are required in the API, the developer needs to pass in the bitmask result to the SDK.
Take the function of obtaining original audio and video data as an example. Examples of using bit masks in different languages are as follows:
enum ZegoAudioDataCallbackBitMask
{
/** This property controls whether the SDK calls back the [onCapturedAudioData] method */
ZEGO_AUDIO_DATA_CALLBACK_BIT_MASK_CAPTURED = 1 << 0,
/** This attribute controls whether the SDK will call back the [onPlaybackAudioData] method */
ZEGO_AUDIO_DATA_CALLBACK_BIT_MASK_PLAYBACK = 1 << 1,
/** This attribute controls whether the SDK calls back the [onMixedAudioData] method */
ZEGO_AUDIO_DATA_CALLBACK_BIT_MASK_MIXED = 1 << 2,
/** This attribute controls whether the SDK will call back the [onPlayerAudioData] method */
ZEGO_AUDIO_DATA_CALLBACK_BIT_MASK_PLAYER = 1 << 3
};
// Open the SDK to obtain the original audio data function, and specify that the SDK needs to trigger the callback of collecting audio data and the callback of playing audio data at the same time
unsigned int bitmask = ZEGO_AUDIO_DATA_CALLBACK_BIT_MASK_CAPTURED | ZEGO_AUDIO_DATA_CALLBACK_BIT_MASK_PLAYBACK;
engine->startAudioDataObserver(bitmask, param);
typedef NS_OPTIONS(NSUInteger, ZegoAudioDataCallbackBitMask) {
/// This property controls whether the SDK calls back the [onCapturedAudioData] method
ZegoAudioDataCallbackBitMaskCaptured = 1 << 0,
/// This property controls whether the SDK will call back the [onPlaybackAudioData] method
ZegoAudioDataCallbackBitMaskPlayback = 1 << 1,
/// This attribute controls whether the SDK calls back the [onMixedAudioData] method
ZegoAudioDataCallbackBitMaskMixed = 1 << 2,
/// This property controls whether the SDK will call back the [onPlayerAudioData] method
ZegoAudioDataCallbackBitMaskPlayer = 1 << 3
};
// Open the SDK to obtain the original audio data function, and specify that the SDK needs to trigger the callback of collecting audio data and the callback of playing audio data at the same time
ZegoAudioDataCallbackBitMask bitmask = ZegoAudioDataCallbackBitMaskCaptured | ZegoAudioDataCallbackBitMaskPlayback;
[[ZegoExpressEngine sharedEngine] startAudioDataObserver:bitmask param:param];
public enum ZegoAudioDataCallbackBitMask {
/** This property controls whether the SDK calls back the [onCapturedAudioData] method */
CAPTURED(1 << 0),
/** This attribute controls whether the SDK will call back the [onPlaybackAudioData] method */
PLAYBACK(1 << 1),
/** This attribute controls whether the SDK calls back the [onMixedAudioData] method */
MIXED(1 << 2),
/** This attribute controls whether the SDK will call back the [onPlayerAudioData] method */
PLAYER(1 << 3);
}
// Open the SDK to obtain the original audio data function, and specify that the SDK needs to trigger the callback of collecting audio data and the callback of playing audio data at the same time
int bitmask = 0;
bitmask |= ZegoAudioDataCallbackBitMask.CAPTURED.value();
bitmask |= ZegoAudioDataCallbackBitMask.PLAYBACK.value();
engine.startAudioDataObserver(bitmask, param);