c語言中的運算符及其含義_按位運算符及其在C語言中與Example一起使用

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.

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

Example:

例:

    4 & 7
4 → 00000100
7 → 00000111
Doing AND for each bit
From LSB:
0 & 1= 0 (LSB of output)
0 & 1= 0
1 & 1= 1
0 & 0 =0
0 & 0 =0
0 & 0 =0
0 & 0 =0
0 & 0 =0
Thus output:
00000100 → 4
4 & 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.

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

Example:

例:

    4 | 7
4 → 00000100
7 → 00000111
Doing OR for each bit
From LSB:
0 | 1 =1 (LSB of output)
0 | 1 =1
1 | 1 =1
0 | 0 =0
0 | 0 =0
0 | 0 =0
0 | 0 =0
0 | 0 =0
Thus output:
00000111 → 7
4 | 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.

它對兩個數字的每一位執行XOR。 如果兩個位不同,則XOR的結果為1。

Example:

例:

    4 ^ 7
4 → 00000100
7 → 00000111
Doing XOR for each bit
From LSB:
0 ^ 1 =1 (LSB of output)
0 ^ 1 =1
1 ^ 1 =0
0 ^ 0 =0
0 ^ 0 =0
0 ^ 0 =0
0 ^ 0 =0
0 ^ 0 =0
Thus output:
00000011 → 3
4 ^ 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.

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

Example:

例:

    4<<1
Before 1 left shift
00000100
After 1 left shift
00001000 → 8
So 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.

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

    4>>1
Before 1 right shift
00000100
After 1 right shift
00000010 → 2
So 4<<1 = 2

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

It takes one operand and inverts all bits of it

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

Example:

例:

    ~4
00000100 → 11111011
~4=251

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

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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/542424.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542424.shtml
英文地址,請注明出處:http://en.pswp.cn/news/542424.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

能上網的Linux系統,那一款linux能上網

zhoushao12 于 2009-02-24 19:13:07發表:linux日常使用中,最重要的就是網絡(本人覺得)特別時ubuntu .但是現在電信偏偏搞什么賬號加密要用互聯星空軟件才可以撥號,更可惡的是這X軟件只有Windws版的!! 使得在linux下撥號上網變得十分麻煩!在網上找了很久終于找到解決方法!!下面拿…

李洪強經典面試題37

1.寫一個NSString類的實現 (id)initWithCString:(c*****t char *)nullTerminatedCString encoding:(NSStringEncoding)encoding; (id) stringWithCString: (c*****t char*)nullTerminatedCString encoding: (NSStringEncoding)encoding { NSString *obj; obj [self al…

new file會創建文件嗎_Rust 文件系統處理之文件讀寫 Rust 實踐指南

Rust 中&#xff0c;文件讀寫處理簡單而高效。代碼也很緊湊&#xff0c;容易閱讀。我們從讀取文件的字符串行、避免讀取寫入同一文件、使用內存映射隨機訪問文件這三個文件處理中的典型案例來了解一下。文件處理場景大家都很熟悉&#xff0c;因此閑言少敘&#xff0c;直接看代碼…

python 打印文件名_在Python中打印文件名,關閉狀態和文件模式

python 打印文件名Prerequisite: Opening, closing a file/open(), close() functions in Python 先決條件&#xff1a; 在Python中打開&#xff0c;關閉文件/ open()&#xff0c;close()函數 1)文件名(file_object.name) (1) File name (file_object.name)) To get the file …

linux搭建直播步驟,Linux 下 nginx + rtmp 搭建直播服務

簡單粗暴直接上步驟吧:注 : 以下示例使用的是nginx(版本1.15.3) rtmp(版本1.2.1)下載nginx和rtmp模塊下載nginx解壓? tar xvf nginx-1.15.3.tar.gz下載nginx rtmp模塊解壓? tar xvf v1.2.1進入nginx目錄? cd nginx-1.15.3執行&#xff1a;#--add-module 指向rtmp模塊目錄,ad…

【Maven學習筆記(二)】Maven的安裝與配置

為什么80%的碼農都做不了架構師&#xff1f;>>> 1、默認本地倉庫路徑 C:\Users\97449\.m2\repository 2、修改本地倉庫路徑 打開D:\apache-maven\conf\settings.xml <?xml version"1.0" encoding"UTF-8"?><!-- Licensed to the Apa…

npm 全局安裝vuecli報錯_cnn explainer本地使用--被npm坑慘

最近在知乎上面看到&#xff0c;看到一個cnn解釋器&#xff0c;把每個步揍都很清楚的展示了出來&#xff0c;我想自己搞來玩玩。第一次使用npm&#xff0c;很多地方不會&#xff0c;第一步&#xff1a;先在網頁上下載下來cnn_explainer&#xff0c;然后解壓在沒有中文路徑的文件…

Python程序從給定的N個數字中找到最大倍數

Here, we will be framing code for finding the maximum multiple of a number x from a given set of a number (set of 5 numbers in this program). 在這里&#xff0c;我們將使用成幀代碼&#xff0c; 從給定的一組數字(此程序中的5個數字組成的集合)中找到x的最大倍數 。…

ubuntu linux本地源,如何制作UbuntuLinux操作系統的本地源?

最簡單制作本地源的方法&#xff1a;在packs文件夾中有如下兩種類型的包&#xff1a;一種是。deb包(全部的依賴包和軟件包)&#xff0c;另一種是Packages。gz著重介紹一下第二個類型的包&#xff1a;在這個包中包含了必需的軟件包列表和依賴信息。這個包是后生成的&#xff0c;…

openmpi安裝_Intel Parallel Studio XE 2019安裝設置

1.Intel Parallel Studio XE 2019簡介Intel Parallel Studio XE 是Intel在單獨一款軟件開發套件中整合了英特爾公司業界領先的 C/C 和 Fortran 編譯器、性能和MPI并行庫、錯誤檢查、代碼健壯和性能分析的工具&#xff0c;有助于大幅提升應用程序性能&#xff0c;同時提高代碼質…

Python | 在列表中指定索引處添加元素的程序

Given a list and we have to add an element at specified index in Python. 給定一個列表&#xff0c;我們必須在Python中的指定索引處添加一個元素。 list.appened() Method is used to append/add an element at the end of the list. But, if we want to add an element …

Linux九大哲學原理,Linux/Unix設計思想(全新闡釋開源哲學,Jon “maddog” Hall作序推薦)...

《Linux/Unix設計思想》第1章  Unix哲學&#xff1a;集思廣益的智慧    11.1  NIH綜合征    21.2  Unix的開發    21.3  Linux&#xff1a;一個人加上一百萬人的智慧    41.4  Unix哲學概述    5第2章  人類的一小步    92.1  準則1&#xff1a;小即是美  …

[Android] 開源View組件(一)

Material Design系列&#xff0c;自定義Behavior實現Android知乎首頁 仿今日頭條最強頂部導航指示器&#xff0c;支持6種模式 MagicIndicator系列之一 —— 使用MagicIndicator打造千變萬化的ViewPager指示器 Android 優雅的為RecyclerView添加HeaderView和FooterView Android …

sql server修改字段編碼格式_關于MySQL如何修改character_set_client的編碼問題

問題引入&#xff1a;我們經常會遇到一些向MySQL數據庫中插入中文&#xff0c;但是select出來的時候&#xff0c;卻發現是亂碼的情況。如我們向表a出入這樣一段記錄&#xff1a;iinsert into a values(‘你好helloworld你好’,’helloworld’);可能當你訪問它的時候&#xff0c…

通用apdu指令_8086微處理器中的通用指令格式

通用apdu指令Introduction: 介紹&#xff1a; In this article, we are going to discuss about the 6 general formats of instructions. 在本文中&#xff0c;我們將討論6種通用指令格式。 One byte instruction: 一字節指令 &#xff1a; This is only one byte long an…

Linux中斷不能進行任務調度,關中斷是否禁止任務調度?關中斷能作為互斥嗎?...

今天再看《嵌入式軟件系統教程》((美)西蒙 著&#xff0c;陳向群 等譯) &#xff0c;里面講到關中斷會關了任務調度&#xff0c;作者沒說原因&#xff0c;我也不知道為什么&#xff0c;所以查了查網絡。在這個網址http://www.hqwic.com/bbs/topic.aspx?topicid11253上有一個討…

Win10系統怎樣讓打開圖片方式為照片查看器

打開注冊表編輯器之后&#xff0c;我們雙擊左側的目錄&#xff0c;依次打開HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft目錄&#xff0c;如下圖所示。 在Microsoft目錄下&#xff0c;我們需要找到Windows Photo Viewer\Capabilities\FileAssociations目錄項&#xff0c;直到看到該子…

python爬蟲開發 從入門到實戰 pdf 謝乾坤_python字符串和整數相互轉換的實例分享...

python 字符串和整數的轉換方法數字轉成字符串方法一&#xff1a;使用格式化字符串:tt322tem%d %tttem即為tt轉換成的字符串常用的格式化字符串&#xff1a;%d 整數%f%F 浮點數%e%E 科學計數%g%G e 和%f/%E 和%F 的簡寫%% 輸出%格式化操作符輔助指令符號 作用* 定義寬度或者小數…

c語言插入排序算法_插入排序算法,流程圖和C,C ++代碼

c語言插入排序算法In the last article, we discussed about the bubble sort with algorithm, flowchart and code. In this article, we are going to discuss about another basic sorting technique i.e. insertion sort. 在上一篇文章中&#xff0c;我們討論了用算法&…

EF使用CodeFirst方式生成數據庫技巧經驗

前言 EF已經發布很久了&#xff0c;也有越來越多的人在使用EF。如果你已經能夠非常熟練的使用EF的功能&#xff0c;那么就不需要看了。本文意在將自己使用EF的方式記錄下來備忘&#xff0c;也是為了給剛剛入門的同學一些指導。看完此文&#xff0c;你應該就學會以CodeFirst的方…