二进制和运营 [英] Binary AND Operations

查看:173
本文介绍了二进制和运营的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图根据MSDN文章有关的&安培;操作

I'm trying to do some Binary AND operations in c# based on MSDN article about & Operator

如果我做的:

1111 & 10 = 2 (0010) // Which is what i expect



然而,

However,

1111 & 100 = 68 (1000100) // Which is **not** what i expect.



我还以为输出本来的 100

我想什么?

推荐答案

您所指定的数字,1111和100,都被视为基地10个号码,而不是二进制数。

The numbers you specified, 1111 and 100, are being treated as base 10 numbers, not binary numbers.

如果您希望二进制整数1111你应该输入 15 ,因为这是该基地10版本。所以:

If you want the binary integer 1111 you should enter 15, as that's the base 10 version. So:

15安培; 4 将成为 4 ,符合市场预期。

15 & 4 will become 4, as expected.

有是在C#中没有语法在指定二进制文字整数。你没有任何选择,但他们自己转换为基地十,或使用运行时转换如通过 Convert.ToInt

There is no syntax in C# for specifying an integer literal in binary. You don't have any choice but to convert them into base ten yourself, or use a runtime-conversion such as through Convert.ToInt.

这篇关于二进制和运营的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆