按位运算符问题...... [英] Bitwise operator question...

查看:84
本文介绍了按位运算符问题......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试图找出这个问题我被问到但是没有运气!

这里的问题是:


" ;编写一个程序,使用任何其他变量交换两个变量的内容,而无需使用
。使用其中一个按位运算符。


我很无能为力......任何帮助都将不胜感激!


谢谢。< br>

I''m trying to figure out this question i was asked but am having no luck!
here''s the question:

"Write a Program that swaps the contents of two variables without
using any other variable. Use one of the bitwise operators."

I''m clueless... Any help would be appreciated!

Thanks.

推荐答案

On Tue,30 Sep 2003 02:57:36 GMT,littlehobo < Li ******** @ tack.com>

在comp.lang.c ++中写道:
On Tue, 30 Sep 2003 02:57:36 GMT, "littlehobo" <Li********@tack.com>
wrote in comp.lang.c++:
我正在努力弄清楚这个问题我被问到但没有运气!
这里的问题是:

编写一个程序,交换两个变量的内容而不使用
任何其他变量。使用其中一个按位运算符。

我很无能......任何帮助都将不胜感激!

谢谢。
I''m trying to figure out this question i was asked but am having no luck!
here''s the question:

"Write a Program that swaps the contents of two variables without
using any other variable. Use one of the bitwise operators."

I''m clueless... Any help would be appreciated!

Thanks.




不要打扰,这是一个废话问题。没有办法做到这一点

保证不会调用未定义的行为。提出问题的人

就像他们想的那样,他们对真正的C或C ++几乎一无所知。


-

Jack Klein

主页: http://JK-Technology.Com

常见问题解答

comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html

comp.lang。 c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++ ftp://snurse-l.org/pub/acllc-c++/faq



Don''t bother, it a crap question. There is no way to do this that is
guaranteed not to invoke undefined behavior. People who ask questions
like this don''t know nearly as much about real C or C++ as they think.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq


Jack Klein写道:
Jack Klein wrote:
2003年9月30日星期二02:57:36 GMT,littlehobo < Li ******** @ tack.com>
在comp.lang.c ++中写道:

On Tue, 30 Sep 2003 02:57:36 GMT, "littlehobo" <Li********@tack.com>
wrote in comp.lang.c++:

我正在尝试弄清楚这个问题我被问到但没有运气!
这里的问题是:

编写一个程序,交换两个变量的内容而不使用
任何其他变量。使用其中一个按位运算符。

我很无能为力......任何帮助都将不胜感激!

谢谢。
I''m trying to figure out this question i was asked but am having no luck!
here''s the question:

"Write a Program that swaps the contents of two variables without
using any other variable. Use one of the bitwise operators."

I''m clueless... Any help would be appreciated!

Thanks.



CLUE:你想要^操作符。

不要打扰,这是一个垃圾问题。没有办法做到这一点,
保证不会调用未定义的行为。那些提问这样的人几乎不会像他们想的那样了解真正的C或C ++。


CLUE: You want the ^ operator.

Don''t bother, it a crap question. There is no way to do this that is
guaranteed not to invoke undefined behavior. People who ask questions
like this don''t know nearly as much about real C or C++ as they think.




什么是未定义的行为?这种类型的东西在图形编程中被大量使用(或者在一个时间内花费了很多时间)。我会对

非常感兴趣,知道你可以从这种技术中得到什么样的意外行为。


NR



What undefined behavior? This type of thing is used (or was at one
time) a lot in graphics programming. I would be very interested in
knowing what kind of unexpected behavior you could get from this technique.

NR


谢谢,回复!我花了一段时间......可能是因为我原本打算用b $ b认为我应该用一个表达式做...我想我正在读

它使用一个按位运算符或者其他的东西。无论如何这就是我提出来的




int a = 5,b = 8; //或任何变量

a ^ = b;

b ^ = a;

a ^ = b;


花了一些时间和纸上哈哈!
Thanks, for the replys! It took me a while...probably because I originally
thought I was supposed to do it with one expression...I guess I was reading
it "use one bitwise operator" or something. Anyway this is what I came up
with:

int a = 5, b = 8; //or whatever variables
a ^= b;
b ^= a;
a ^= b;

that took some time and paper lol!


这篇关于按位运算符问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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