Redian新闻
>
What is the methology to solve problems like swapping variables?
avatar
What is the methology to solve problems like swapping variables?# Programming - 葵花宝典
k*r
1
For example, if we want to use bit operations to swap two variables without
using temporary variable. Any one can tell me how to develop an approach to
using bit operations to solve such problems step by step. Because the bit
operations usually don't look intuitive so the thread of thoughts behind that
is very important in mastering bit operations. Thanks so much for your
tutorial.
avatar
r*p
2
a ^= b;
b ^= a;
a ^= b;

that

【在 k******r 的大作中提到】
: For example, if we want to use bit operations to swap two variables without
: using temporary variable. Any one can tell me how to develop an approach to
: using bit operations to solve such problems step by step. Because the bit
: operations usually don't look intuitive so the thread of thoughts behind that
: is very important in mastering bit operations. Thanks so much for your
: tutorial.

avatar
k*r
3
Can you tell me how you get it? I guess it is more important than the answer.

【在 r******p 的大作中提到】
: a ^= b;
: b ^= a;
: a ^= b;
:
: that

avatar
r*p
4
(a^b)^b = a, with reflexivity

.

【在 k******r 的大作中提到】
: Can you tell me how you get it? I guess it is more important than the answer.
avatar
l*t
5
Actually, it is associativity for ^:
(a^b)^b = a^(b^b) = a^0 = a

【在 r******p 的大作中提到】
: (a^b)^b = a, with reflexivity
:
: .

avatar
r*p
6
以前有人贴过一个特全面介绍的link,找不到了

【在 l***t 的大作中提到】
: Actually, it is associativity for ^:
: (a^b)^b = a^(b^b) = a^0 = a

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。