Two’s-complement System
Two’s-complement system is the most common method of representing signed integers on computers. The alternatives are One’s complement, Sign-and-magnitude and Biased representation. An N-bit two’s-complement system can represent every signed interger in the range from -2^(N-1) to 2^(N-1)-1.
Negating a two’s complement number is simple: Invert all the bits and add one to the result. For 32-bit integer, negating 0xFFFF, we get 0×0000 + 1 = 1. Therefore, 0xFFFF must represent -1. Thus, when we use _mm_set1_epi8(-1), which is defined in SSE library, it will set 16 singned 8-bit integer value to 0xFF.
Right-shift negtive integer will always set the highest bit. So, right-shift -1 will always get -1. The following is the result after -1 left-shift 31 bit.
#include <stdio.h>
int main()
{
signed int a;
a = -1;
printf(“a is %d\n”,a);
a = a << 31;
printf(“a is now %d\n”,a);
return 0;
}
a is -1
a is now -2147483648
Discussion Area - Leave a Comment