fastest way to negate a number

后端 未结 7 1697
南旧
南旧 2020-12-29 03:20

I was thinking this morning here, what would be the fastest way to reverse a number of positive to negative and from negative to positive, of course, the simplest way might

7条回答
  •  执笔经年
    2020-12-29 03:39

    You can try

    int a = 10;
    a= ~a+1;
    

    but you shouldn't worry about that, because compiler makes it in the best way.

提交回复
热议问题