There is a binary string 10001110 which I know is using 2’s complement. I know it will be 8 bits.
It is given to me in the form of an unsigned int which equals 142.
I then need to convert this back to 10001110
then invert all the bits and add one resulting in it equaling 01110010
and then convert this to a signed int equaling -114.
How can I do this? I’m relatively new to C and have spent ages trying to figure it out!
Essentially I want to write a function that takes the unsigned int 142 and returns the signed int -114
Here’s the solution I finally came up with.
Thanks for the help everyone!