Day 16th: C-Step arithmetic and inline assembly

Source: Internet
Author: User
Tags bitwise

  Bit operations are often encountered in driver development, especially in the 0 and 1 positions. You can change the number of bits you specify, and you cannot change the value of other bits. You also need to write your code efficiently. This is a very important skill.  There are several symbols in the bitwise operation: | Bitwise OR & Bitwise AND ^ XOR ~ bitwise NON

1#include <stdio.h>2 3 intMain ()4 {5     intA =0x1101;6     intb =0x1011;7     intc =9;8printf"A | b is%x\n", a |b);9printf"A & B is%x\n", A &b);Tenprintf"a ^ b is%4x\n", a ^b); Oneprintf"~c is%d\n",~c); A  -}

The result is a | B is 1111 A & B are 1001 a ^ B is ~c is-10

The first three results are no problem, the last answer should be focused on understanding. First of all, 9 is written in hexadecimal 0x00000101 to take the non-word is 0xfffffefe. Because C is signed, the highest one is 1 for negative numbers, and negative numbers are shown in the form of a complement in the computer. So to output the decimal number, we need to get the complement-1 ratio first.

Day 16th: C-Step arithmetic and inline assembly

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.