日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言中的运算符及其含义_按位运算符及其在C语言中与Example一起使用

發(fā)布時間:2025/3/11 编程问答 64 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言中的运算符及其含义_按位运算符及其在C语言中与Example一起使用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

c語言中的運算符及其含義

1)&(按位與) (1) & (bitwise AND))

It does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1.

它對兩個數(shù)字的每一位進行“與”運算。 僅當兩個位均為1時,AND的結(jié)果才為1。

Example:

例:

4 & 74 → 000001007 → 00000111Doing AND for each bitFrom LSB:0 & 1= 0 (LSB of output)0 & 1= 01 & 1= 10 & 0 =00 & 0 =00 & 0 =00 & 0 =00 & 0 =0Thus output:00000100 → 44 & 7 =4

2)| (按位或) (2) | (bitwise OR))

It takes two numbers as operands and does OR on every bit of two numbers. The result of OR is 1 any of the two bits is 1.

它使用兩個數(shù)字作為操作數(shù),并對兩個數(shù)字的每一位進行“或”運算。 OR的結(jié)果為1,兩個位中的任何一個為1。

Example:

例:

4 | 74 → 000001007 → 00000111Doing OR for each bitFrom LSB:0 | 1 =1 (LSB of output)0 | 1 =11 | 1 =10 | 0 =00 | 0 =00 | 0 =00 | 0 =00 | 0 =0Thus output:00000111 → 74 | 7 =7

3)^(按位XOR) (3) ^ (bitwise XOR))

It does XOR on every bit of two numbers. The result of XOR is 1 if the two bits are different.

它對兩個數(shù)字的每一位執(zhí)行XOR。 如果兩個位不同,則XOR的結(jié)果為1。

Example:

例:

4 ^ 74 → 000001007 → 00000111Doing XOR for each bitFrom LSB:0 ^ 1 =1 (LSB of output)0 ^ 1 =11 ^ 1 =00 ^ 0 =00 ^ 0 =00 ^ 0 =00 ^ 0 =00 ^ 0 =0Thus output:00000011 → 34 ^ 7 =3

4)<<(左移) (4) << (left shift))

It takes two operands, left shifts the bits of the first operand, the second operand decides the number of places to shift. In every left shift all bits are shifted to left adding a logical 0 at LSB.

它需要兩個操作數(shù),左移第一個操作數(shù)的位,第二個操作數(shù)確定要移位的位數(shù)。 在每個左移中,所有位都向左移,在LSB處加邏輯0。

Example:

例:

4<<1Before 1 left shift00000100After 1 left shift00001000 → 8So 4<<1 = 8

5)>>(右移) (5) >> (right shift))

It takes two numbers, right shifts the bits of the first operand, the second operand decides the number of places to shift.

它需要兩個數(shù)字,右移第一個操作數(shù)的位,第二個操作數(shù)確定要移位的位數(shù)。

4>>1Before 1 right shift00000100After 1 right shift00000010 → 2So 4<<1 = 2

6)?(按位非) (6) ~ (bitwise NOT))

It takes one operand and inverts all bits of it

它需要一個操作數(shù)并將其所有位求反

Example:

例:

~400000100 → 11111011~4=251

翻譯自: https://www.includehelp.com/c/bitwise-operators-and-their-working-with-examples-in-c.aspx

c語言中的運算符及其含義

總結(jié)

以上是生活随笔為你收集整理的c语言中的运算符及其含义_按位运算符及其在C语言中与Example一起使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。