C++に"===="のようなビット単位のコンパレータがないのはなぜですか?毎回変数をキャストする必要がありますか?
(注:私はすでに論理算術演算子を知っていて、別のことを探しています。ちなみに、算術xor a ^^ bもありません:)私はa&bをa(またはb)に対して、a^bをゼロに対してチェックできることを知っています、...)
#include "stdafx.h"
#include<iostream>
#include<stdlib.h>
int main()
{
char a=-1;
unsigned char b=0;
for(b=0;b<255;b++)
{
if(a==b)std::cout<<(int)b; //cannot find 11111111)2==11111111)2
//ok, it looks -1==255 surely
//if(a====b)std::cout<<" bitwise equal "; could be good
}
bool compare=true;
bool bit1=false,bit2=false;
unsigned char one=1;
b=255; //bit-swise equal to a
for(int i=1;i<7;i++)
{
bit1=(a>>i)&one;
bit2=(b>>i)&one;
if(bit1!=bit2){compare=false;return;}//checks if any bit is different
}
if(compare)std::cout<<(int)b; //this writes 255 on screen
getchar();
return 0;
}
ありがとう。
私はできたはずです:
__asm
{
push push....
mov al,[a]
mov dl,[b]
cmp al,dl //this is single instr but needs others
je yes
mov [compare],false
jmp finish
yes:
mov [compare],true
jmp finish
finish:
pop pop...
膨張したコード...