I know that many basic operations, such as addition or division, can also be implemented in C using only bitwise operators. How can I do the same with a greater or equal sign (> =)?
if (x >= 0) { ... }
The simplest solution I can come up with:
#include <limits.h> if ((x & INT_MAX) == x) // if (x >= 0) ...
If you don't like it ==, then use XOR to run the equals test:
==
#include <limits.h> if ((x & INT_MAX) ^ x) // if (x < 0) ... else // else x >= 0 ...
If you want only if (x >= 0)this is enough
if (x >= 0)
if (~x & INT_MIN)
If you mean "more or equal" between the two numbers in general, then this is much more than the difference
If all you can use is bitwise operators, and even comparison operators are disabled, this is not possible (in fact, almost nothing would have been possible). Implicit comparison is always present, even operations, such as if(x some bitwise stuff), are actually interpreted as equivalent if(x some bitwise stuff) != 0)in the generated assembler code.
if(x some bitwise stuff)
if(x some bitwise stuff) != 0)
Source: https://habr.com/ru/post/1696392/More articles:How to programmatically iterate over datagrid rows? - winformsWith which flexible software development methods have you been most successful? - methodsHow to make Flash movie with transparent background - firefoxAudio and video transcoding - flvWhat is the best way to get columns for my user group? - .netHow can I improve the editing-compilation cycle when developing a SharePoint workflow? - workflowMore than a function in C - cWhat are the options for delivering Flash videos? - flashpoll table locking schemes in T-SQL - tsqlИмпорт пространства имен System.Query - asp.netAll Articles