100% found this document useful (1 vote)
30 views

Bit Twiddling

A document discusses three methods for determining the sign of an integer in C/C++. The first method returns 0 if the number is positive and -1 if negative using the expression sign = - (num < 0). The second method shifts the number right by the size of an integer minus one, returning -1 for negative numbers. The third method is not fully explained.

Uploaded by

preetamn
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
30 views

Bit Twiddling

A document discusses three methods for determining the sign of an integer in C/C++. The first method returns 0 if the number is positive and -1 if negative using the expression sign = - (num < 0). The second method shifts the number right by the size of an integer minus one, returning -1 for negative numbers. The third method is not fully explained.

Uploaded by

preetamn
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Uppercase character can be converted to lowercase by setting the 5th bit to 1 Determining the sign of a integer 1.

sign = - (num < 0); returns 0 if +ve and -1 if ve to return 1 or -1 result we can have expression like sign = - (num < 0) | 1; 2. sign = num >> (sizeof(int) * CHAR_BIT -1); shifting 31 gives a result -1 for negative number 3.

You might also like