Bitwise right shift operator in C#

王林
Release: 2023-09-15 18:13:02
forward
1194 people have browsed it

C# 中的按位右移运算符

#Bitwise operators act on bits and perform bitwise operations. In the bitwise right shift operator, the value of the left operand is shifted to the right by the number of bits specified by the right operand.

In the code below, we have the value -

60 i.e. 0011 1100
Copy after login

shift right %minus;

c = a >> 2;
Copy after login

shift right twice and convert to 15 -

15 i.e. 0000 1111
Copy after login

Example

You can try running the following code to implement the bitwise right shift operator in C#-

using System;
using System.Collections.Generic;
using System.Text;
namespace Demo {
   class toBinary {
      static void Main(string[] args) {
         int a = 60;    /* 60 = 0011 1100 */
         int b = 0;
         c = a >> 2;    /* 15 = 0000 1111 */
         Console.WriteLine("Value of b is {0}", b);
         Console.ReadLine();
      }
   }
}
Copy after login

The above is the detailed content of Bitwise right shift operator in C#. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!