我是个白痴吗? [英] Am I an idiot?

查看:56
本文介绍了我是个白痴吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个反复的问题。但是这个陈述不应该在变量a中存储三个值的价值:


#include< iostream>

int main()

{

int a = 1& 2;

if(a& 1)

{

std :: cout<< 一个 << std :: endl;

}

if(a& 2)

{

std :: cout << 两个 << std :: endl;

}

返回0;

}


我是尝试使用位掩码传递带整数的标志,然后

用if检查它们(整数& flagX)


发生了什么事?


非常感谢你的时间,

Kevin Grigorenko

That''s a rethorical question. But shouldn''t this statement store the value
of three in the variable a:

#include <iostream>

int main()
{
int a = 1 & 2;
if(a & 1)
{
std::cout << "One " << std::endl;
}
if(a & 2)
{
std::cout << "Two " << std::endl;
}
return 0;
}

I''m trying to use bit-masking to pass around flags with an integer, and then
check them with if( integer & flagX )

What is going on?

Thanks a lot for your time,
Kevin Grigorenko

推荐答案

Kevin Grigorenko写道:
Kevin Grigorenko wrote:

这是一个重要的问题。但是这个陈述不应该在变量a中存储三个值



否则它应该存储值0.

#include< iostream>

int main()
{
int a = 1& 2;

That''s a rethorical question. But shouldn''t this statement store the value
of three in the variable a:
No. It should store the value 0.

#include <iostream>

int main()
{
int a = 1 & 2;




你想要


int a = 1 | 2;

使用|设置位,使用&清除位或检查

a位是否设置。

-

Karl Heinz Buchegger
kb ****** @ gascad.at


Kevin Grigorenko在新闻中写道: br**********@f04n12.cac.psu.edu:
Kevin Grigorenko wrote in news:br**********@f04n12.cac.psu.edu:
这是一个重要的问题。但是这个语句不应该在变量a中存储三个值:

#include< iostream>

int main()
{
int a = 1& 2;


int a = 1 | 2;

if(a& 1)
{
std :: cout<< 一个 << std :: endl;
}
if(a& 2)
{
std :: cout<< 两个 << std :: endl;
}
返回0;
}
我正在尝试使用位掩码来传递带整数的标志,
然后用if(整数& flagX)检查它们

是怎么回事?
That''s a rethorical question. But shouldn''t this statement store the
value of three in the variable a:

#include <iostream>

int main()
{
int a = 1 & 2;
int a = 1 | 2;
if(a & 1)
{
std::cout << "One " << std::endl;
}
if(a & 2)
{
std::cout << "Two " << std::endl;
}
return 0;
}

I''m trying to use bit-masking to pass around flags with an integer,
and then check them with if( integer & flagX )

What is going on?




& (又名bitwise和aka bitand)这两件事都必须是真的(或者设置在

按位意义上)。


| (又名bitwise或aka bitor)一个(或两个)必须是真的(或......)


HTH。


Rob。

-
http:// www.victim-prime.dsl.pipex.com/


" Karl Heinz Buchegger" < KB ****** @ gascad.at>在消息中写道

新闻:3F *************** @ gascad.at ...
"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:3F***************@gascad.at...
Kevin Grigorenko写道:
Kevin Grigorenko wrote:

这是一个重要的问题。但是这个语句不应该在变量a中存储三个
的值:
不应该存储值0.

That''s a rethorical question. But shouldn''t this statement store the value of three in the variable a:
No. It should store the value 0.

#include< iostream>

int main()
{
int a = 1& 2;

#include <iostream>

int main()
{
int a = 1 & 2;



你想要

int a = 1 | 2;



You want

int a = 1 | 2;




啊,所以我是个白痴。我知道。哈哈,哇,我出了什么问题

今天。


使用|设置位,使用&清除位或检查是否设置了一下。

-
Karl Heinz Buchegger
kb ****** @ gascad.at




感谢它,

Kevin Grigorenko



Appreciate it,
Kevin Grigorenko


这篇关于我是个白痴吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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