I am not specific about any algorithm or program. But considering bit manipulation programs and other tasks that involves 2's complement or 1's complement etc., what if the negative numbers are represented (in memory or wherever) in a way opposite to the assumptions of the programmer. Does this scenario even occur? If yes, then how can it be handled.
Does this scenario even occur?
Yes, before C++20 that is allowed and there have been architectures that don't use two's complement in the past. However since C++20 two's complement representation is mandated.
If yes, then how can it be handled.
By not relying on operations with implementation-defined behavior or by asserting that your code may only be used on two's complement architectures.