2 ms·
Having started with assembly programming, I see 'signed' and 'unsigned' as just two different views on the same 'sign-agnostic' bag of bits (which of course is
by flohofwoe 3y ago
Having started with assembly programming, I see 'signed' and 'unsigned' as just two different views on the same 'sign-agnostic' bag of bits (which of course is the whole point of 2's-complement), a bit like Schroedinger's Cat: a number is neither signed nor unsigned until you look at it.
From that point of view (that signedness is just a different view on the same bits) it's a bit weird that 'signedness' ended up in type systems of high level languages, and isn't just a printf formatting feature (the only other place where signedness matters is when extending narrow integers to wider integers, where the top-most bit either needs to be set to zero for 'unsigned' or replicated for 'signed').
- pwdisswordfishc 3y agoHave you ever performed division?
- flohofwoe 3y agoI haven't done the binary math to figure it out so far, but I wonder if signed vs unsigned division is also just doing an internal sign-extension to a wider type before the actual 'sign-agnostic' operation (e.g. a special case of the general sign-extension to a wider type). But as I said, not completely sure if that's the case, or if there are two entirely different hardware blocks for signed vs unsigned division. Same for muls vs mulu btw.
- fanf2 3y agoIt matters for comparison! For example, arm asm has HI HS LS LO for unsigned comparison and GT GE LE LT for signed comparison.