go***********@yahoo.co.uk (Patrick) writes:
I have the following problem,
(1) I have an 8-Bit microcomputer
(2) It has an integer word size of 2bytes (=16 bits)
(3) So int type is in the range -32768 to +32767
(4) Now I want to add numbers of type int, in the range 0 to 50000
How do I deal with the range limitation here?
I can ONLY use int type.
Why can you only use int?
We see a lot of questions here of the form:
I need to do <some task> *without* using <the most obvious tool>.
How can I do this?
In your case, the most obvious tool is unsigned int (guaranteed to
have a range of at least 0 to 65535) or long (guaranteed to have a
range of at least -2147483647 to +2147483647).
We can be a lot more helpful if we know *why* you "can ONLY use int
type". If it's a puzzle, some of us might actually be interested in
helping you to solve it. If there's a good reason for the
restriction, knowing what that reason is will help us guess what other
constraints might or might not apply. If it's a homework assignment
(as some, but not all, of these questions turn out to be), the point
is for you to figure it out for yourself, though we'd be happy to
submit solutions directly to your instructor on your behalf. If it's
not a homework assignment, please ignore the previous sentence, which
was deliberately sarcastic.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"