You forgot to mention the little 3 next to 10110. That's 10110 base 3, not base 2. I would take it to base 2, do the 2's complement, then take it back to base 3.The 2's complement of 10110 is the main one that is stumping me.
I also tend to disagree with saying that (unsigned char) or (char)[a large or small number] is "invalid" or "out of range". As an example, (unsigned char)36006925 (your post number) may or may not generate a compiler warning, but it will also return 13. But you know your professor better than I do.
They aren't learning casting, they're learning simple binary representation. One of the fundamental concepts is that you can only represent a limited range of values.
You forgot to mention the little 3 next to 10110. That's 10110 base 3, not base 2. I would take it to base 2, do the 2's complement, then take it back to base 3.
Just IMHO, they are teaching you lots of useless stuff. Nobody uses anything other than 1's complement (~) and 2's complement (-).
Edit: For Lab 8 Page 1, a lot of that is wrong. Consider: an unsigned 4-bit value can store 16 values, 0 through 15, as you correctly stated on Lab 6. Now, a signed 4-bit value can also store 16 values, and only one of those is zero. :whiste:
I also tend to disagree with saying that (unsigned char) or (char)[a large or small number] is "invalid" or "out of range". As an example, (unsigned char)36006925 (your post number) may or may not generate a compiler warning, but it will also return 13. But you know your professor better than I do.
On Lab 8 on the first page, wouldn't you only count the first 3 spots since the 4th is the indicator of it being negative or positive?
It's not quite that simple. Why don't you try this?
1. For a 4-bit value, start counting 0, 1, 2 in binary, until you get to something that would represent a negative number.
2. What is that number? If you think it's -1, think again. 😉 And remember, -0 only happens in floating point.
3. If you still think Lab 8 is right, try the reverse, counting 0, -1, -2 in binary, until you get to something that would represent a positive number.
Edit: Or even simpler, enumerate all the decimal values of a two-bit signed integer. How many of them are there? Only one is "zero". What are the rest?
😵 Next they'll be teaching BCD. D:The instructions on that page tell them to use a sign magnitude representation
😵 Next they'll be teaching BCD. D: