I was practicing for all the logic gate implementations for bits and then I started to implement NOR but I don't know why it is giving negative values for using '~' operator. It did give the proper results when I used '!' operator. I am not able to find the logic behind what is wrong with what I am doing.
I read through operators in C++ and clearly mentions that to reverse a bit using '~' operator and '!' for logical operations
void NOR(vector<string>& input){ // input is string of vectors with values 0 0, 0 1, 1 0, 1 1
cout<<"---------------------------------"<<endl;
for(auto& i : input){
cout<<"NOR of "<<i[0]<<" "<<i[1];
cout<<" is "<<~((i[0]-'0') | (i[1]-'0'))<<endl;
}
cout<<"---------------------------------"<<endl;
}
The results which I am getting is
NOR of 0 0 is -1
NOR of 1 0 is -2
NOR of 0 1 is -2
NOR of 1 1 is -2