Can an example of bitwise subtraction be in code? I do not really understand what I mean.

  • Can subtraction without a loan from the previous category, well, so this is a logical XOR, denoted by ^ - Mike
  • @Mike I understand it is necessary, Stobikom - Zhenya
  • @Artem is a bitwise subtraction of numbers (roughly speaking, like a school, in a column) for long numbers, okay? -
  • @Artem, in my opinion, for large numbers you need your own classes with their own arithmetic. Not clear remained the scope. - LXA
  • Bitwise - binary or decimal? - maestro

1 answer 1

For example:

 #include <stdio.h> int main() { unsigned char x = 0b00000100, y = 0b00000010; unsigned char res, carry = 0; unsigned char n; unsigned char xx, yy; for (n = 0; n < 8; ++n) { xx = x & 1 ? 0xFF: 0; yy = y & 1 ? 0xFF: 0; res = carry ? (~(xx^yy)) : xx^yy; carry = carry ? ((~xx)|yy) : ((~xx)&yy); printf( res ? "1" : "0" ); x >>= 1; y >>= 1; } printf("\r\n"); return 0; } 
  • I'm afraid to even ask, is it ab? - pavel
  • This is x - y ........ - Vanyamba Electronics
  • just looks scary to say the least. I just do not believe that this is optimal ... - pavel
  • one
    The C language is simply not very adapted for working with discharges. So you have to imitate Verilog. - Vanyamba Electronics