![]() You can force cast the bits from one to the other, to see both values, but at that moment in time, its signed or not, and has one of the 2 values at that moment. They are the same number, but if you look at the ranges, the large value DOES NOT EXIST in the range for signed values for that type - so it can only be one of the two, the large unsigned value, or the small negative value - not both. if you promote a negative value to a larger, negative type, some of the high order bits get set in the process of making it negative, and that makes it a gigantic value in your case. Here you are seeing a combined effect of using different sized types and using signed and unsigned. ![]() But when you tell the compiler that it is signed, it knows that 128 is really a negative number, or that 253 is a negative number, etc. The same bits exist for both (8 bits of 1s and 0s). eg for a simple byte, you have -127 to 127 or 0-255. You will see something (now that you are looking for it!): the unsigned version's biggest value is about twice that of the signed value. If you look up a table of ranges (what numbers the variables of different types in c++ can be) This is critical, if you do not understand it, you need to stop until you do. ![]() So how is it possible when these values are different, that the output is the same when I convert them to hex?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |