If you don't need a portable version, you can abuse the knowledge that integers are almost always 4 bytes.
return 0x80000000;
In fact, if you know the size of the type you're going to return, you can skip the bitwise game and cheat with the format:
- In 0x__, each number is 4 bits.This means 2 digits are one byte.
- You want the first bit to be 1, and all other bits to be 0.
- 0x8 = 0b1000
- As such, you can represent the value as 0x80 + 2 '0's for every byte of the type past the first.
But to answer the rest of your question.
How would I go about doing this?
If you're templating, you'd (probably) use the bitwise trick the other answer suggests. Otherwise you can cheat with the above code or use a definition from limits.h (iirc).
~ (~0u >> 1);
Would be a portable solution.
Wouldn't the most negative two's comp number be dependent on how many bits the selected number is?
The most negative two's compliment is dependent upon the size of the containing variable, so I suppose you could say "selected number". In fact, the range of values depends on the size of the containing variable.
For instance, 10000 would be the most negative two's comp number of a 16 bit int?
For 16 bits, the most negative two's comp would be 0x8000, 0b1000000000000000 or -32768, depending on how you'd like it represented.
!and+are not bitwise operators. Are we to take you to mean simply that the list you've given comprises all the operators you are permitted to use?intvalue that is most negative (has the minimum value of allintvalues) using at most four of the operators listed.(signed)(~(~0U>>1))But beware that this implies your internal representation is two's complement. Otherwise, you'll get U.B.