In the C language, signed digits are shifted

Source: Internet
Author: User

#include <stdio.h>intMainvoid) {unsigned i=0XCFFFFFF3; Longj=0XCFFFFFF3; intk=0XCFFFFFF3; printf ("num:\t%x\n",0XCFFFFFF3>>2); printf ("i:\t%x\n", I >>2); printf ("j:\t%x\n", J >>2); printf ("k:\t%x\n", K >>2);}

Print results

SH-3.2#./A.outnum:    33fffffci:    33fffffcj:    33fffffck:    F3FFFFFC

Unsigned 0xcffffff3 converted to binary 1100 1111 1111 1111 1111 1111 1111 0011

Two-bit right shift 0011 0011 1111 1111 1111 1111 1111 1100 converted to 16 binary to 0X33FFFFFC

If there is a sign

1100 1111 1111 1111 1111 1111 1111 0011 right shift after 1111 0011 1111 1111 1111 1111 1111 1100

Convert to 16 binary: 0XF3FFFFFC

That is, the symbol, no matter how many right shift, not the highest 1, but each time the right shift when the highest bit is 1

In the C language, signed digits are shifted

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.