Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
x86 assembly language (FASM). The argument and the result are in eax register.
It works properly for -2E302^30 < N < +2E30+2^30-1
16 bytes executable code.
use32 f_n: lea edx, [2*eax] xor edx, eax btc eax, 30 shl edx, 1 jnc .end neg eax .end: retn
It works properly for -2E30 < N < +2E30-1
It works properly for -2^30 < N < +2^30-1