前言:Binary XOR Operator copies the bit if it is set in one operand but not both.二进制XOR运算符复制该位,如果它在一个操作数中设置,但不是两个操作数。
VB.Net - 移位运算符如何学习,怎么样了解VB.Net - 移位运算符方面的知识点!
假设变量A保持60,变量B保持13,则:
| 运算符 | 描述 | 示例 |
|---|---|---|
| And |
Bitwise AND Operator copies a bit to the result if it exists in both operands. 如果两个操作数都存在,则位与运算符将一个位复制到结果。 |
(A AND B) will give 12, which is 0000 1100 |
| Or |
Binary OR Operator copies a bit if it exists in either operand. 二进制OR运算符复制一个位,如果它存在于任一操作数。 |
(A Or B) will give 61, which is 0011 1101 |
| Xor | Binary XOR Operator copies the bit if it is set in one operand but not both.二进制XOR运算符复制该位,如果它在一个操作数中设置,但不是两个操作数。 | (A Xor B) will give 49, which is 0011 0001 |
| Not |
Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. 二进制补码运算符是一元的,具有“翻转”位的效果。 |
(Not A ) will give -61, which is 1100 0011 in 2's complement form due to a signed binary number. |
| << |
Binary Left Shift Operator. The left operand's value is moved left by the number of bits specified by the right operand. 二进制左移位运算符。 左操作数的值向左移动由右操作数指定的位数。 |
A << 2 will give 240, which is 1111 0000 |
| >> |
Binary Right Shift Operator. The left operand's value is moved right by the number of bits specified by the right operand. 二进制右移运算符。 左操作数的值向右移动由右操作数指定的位数。 |
A >> 2 will give 15, which is 0000 1111 |
尝试以下示例来了解VB.Net中提供的所有位运算符:
Module BitwiseOp
Sub Main()
Dim a As Integer = 60 ' 60 = 0011 1100
Dim b As Integer = 13 ' 13 = 0000 1101
Dim c As Integer = 0
c = a And b ' 12 = 0000 1100
Console.WriteLine("Line 1 - Value of c is {0}", c)
c = a Or b ' 61 = 0011 1101
Console.WriteLine("Line 2 - Value of c is {0}", c)
c = a Xor b ' 49 = 0011 0001
Console.WriteLine("Line 3 - Value of c is {0}", c)
c = Not a ' -61 = 1100 0011
Console.WriteLine("Line 4 - Value of c is {0}", c)
c = a << 2 ' 240 = 1111 0000
Console.WriteLine("Line 5 - Value of c is {0}", c)
c = a >> 2 ' 15 = 0000 1111
Console.WriteLine("Line 6 - Value of c is {0}", c)
Console.ReadLine()
End Sub
End Module
当上述代码被编译和执行时,它产生以下结果:
Line 1 - Value of c is 12
Line 2 - Value of c is 61 Line 3 - Value of c is 49 Line 4 - Value of c is -61 Line 5 - Value of c is 240 Line 6 - Value of c is 15
文章出自:http://qh.itpxw.cn/peixun/software/201946961.html
文章标题:VB.Net - 移位运算符如何学习
免责声明:本站文章均由入驻起航学习网的会员所发或者网络转载,所述观点仅代表作者本人,不代表起航学习网立场。如有侵权或者其他问题,请联系举报,必删。侵权投诉
IT培训网 访问该机构站点 报名留言 加为好友 用户等级:注册会员
用户级别:10
机构名称:IT培训网
联 系 人:罗老师
联系电话:13783581536
联系手机:13783581536
在线客服:
在 线 QQ:
电子邮件:
网站域名:http://www.itpxw.cn
注册时间:2016-07-18 11:07
最后登录:2024-02-20 13:02
Java定义方法的格式是什么?IT培训网小编来告诉大家。所谓方法...
大家在Java教程中会学到关于Java消息推送的知识,那么,Java消息...
常用的Java日期格式转换有哪些?IT培训网小编来告诉大家。 1...
Java创建对象数组的方法是什么?IT培训网小编来告诉大家。Ja...