Shift operation in C #

Source: Internet
Author: User

Shift operation in C #

In the computer, the negative numbers in the signed type are stored in the form of binary complement. How can we obtain the decimal value of the binary number in the form of this complement?

1) The bitwise (including the sign bit) of the number in the binary complement form is reversed, and then 1 (binary operation ).

2) Calculate the decimal value of the obtained number as an unsigned number, and add a symbol before it.

========================================================== ==========================================================

// 1: 0 0000000 00000000 00000000 00000001

//-1: 1 0000000 00000000 00000000 00000001 (original code)
//-1: 1 1111111 11111111 11111111 11111111 (Supplemental code)

//-2: 1 0000000 00000000 00000000 00000010 (original code)
//-2: 1 1111111 11111111 11111111 11111110 (Supplemental code)

Int num =-2;

Int ret = num> 1;

Console. writeline (RET );

// For the shift operation in C #, it is for the "binary storage as a whole" of the number in the computer.
//
// <(Left shift) indicates the entire left shift. All spaces that are empty on the right are filled with zeros.
//> (Right shift): 1. Number of unsigned characters
// Shifts the entire right, and all the spaces empty on the left are filled with zeros.
// 2. Number of symbols
// Shifts the entire right. All the null bits on the left fill in the signed bits of this number.
//
// The result is the binary number.

========================================================== ==========================================================

Shift operations in javascript:

<(Left shift)> (right shift): If it is an unsigned number, it doesn't matter. Move it as a whole. If there is a number of symbols, the symbols do not move.

>>> (Right shift of the unsigned number): All values are considered as unsigned numbers, and the empty bits on the left are filled with 0. (Returns the number of unsigned types)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.