码迷,mamicode.com
首页 > 其他好文 > 详细

位运算及其应用详解

时间:2016-05-11 19:52:21      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

http://blog.chinaunix.net/uid-21411227-id-1826986.html

负数的二进制为该负数取反之后加一,即:-n=(~n+1)

二进制的打印:

技术分享
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <conio.h>
 6 using namespace std;
 7 int show(char ch[])
 8 {
 9     cout<<ch<<endl;
10     return 0;
11 }
12 int main()
13 {
14     char ch[4];
15     int n,m;
16     n=10;
17     itoa(n,ch,11);
18     show(ch);
19     m=15;
20     itoa(m,ch,2);
21     show(ch);
22     itoa(m&n,ch,2);
23     show(ch);
24     itoa(~n+1,ch,2);
25     show(ch);
26     itoa(-n,ch,2);
27     show(ch);
28     return 0;
29 }
View Code

 

位运算及其应用详解

标签:

原文地址:http://www.cnblogs.com/wang-ya-wei/p/5483203.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!