473,395 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

range limitation

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.

any help appreciated!

pat
Nov 14 '05 #1
5 1086

"Patrick" <go***********@yahoo.co.uk> a écrit dans le message de
news:94**************************@posting.google.c om...

Hi,
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
Is your system complies with any C standard?
How do I deal with the range limitation here?
I can ONLY use int type.
I'm not sure about what you mean by using only the int type, since the
storage of the unsigned int type (probably a range from 0 to 65535 according
your third point) is the same of the int type, altough they are different.

Regis

any help appreciated!

pat

Nov 14 '05 #2
On 24 Apr 2004 15:06:49 -0700, go***********@yahoo.co.uk (Patrick)
wrote in comp.lang.c:
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.

any help appreciated!

pat


Get a new job, your current one is unreasonable.

If you have a C compiler, it supports signed and unsigned longs, which
must have at least 32 bits. If it does not support signed and
unsigned long, it is not a C compiler, no matter what the people who
make it say.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Patrick wrote:
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.
In your implementation, int can hold one of 65,536 possible values
You have a requirement to be able to hold at least 50,001 possible values in an int.
What's the problem?

I can see two alternatives, and I'm sure that there are more.
1) store your values in an int, using excess-32768 notation, or
2) use unsigned int values, which on your implementation /should/ be
able to range from 0 to 65,535 (15,535 more than you require)

any help appreciated!

pat

- --
Lew Pitcher
IT Consultant, Enterprise Application Architecture,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFAjPxaagVFX4UWr64RAvhGAKDhi07pgP3YGRYty7SGi4 t+tI5/PwCfe/3T
/9Qtwys3uQLdidqB7f50EkY=
=Rqi5
-----END PGP SIGNATURE-----
Nov 14 '05 #4
"Lew Pitcher" <Le*********@td.com> wrote in message
news:sZ*******************@news20.bellglobal.com.. .
[snip]
I can see two alternatives, and I'm sure that there are more.
1) store your values in an int, using excess-32768 notation, or
2) use unsigned int values, which on your implementation /should/ be
able to range from 0 to 65,535 (15,535 more than you require)


That's a 'must', not a 'should'; 65535 is the minimum for UINT_MAX (and
USHRT_MAX).
Nov 14 '05 #5
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"
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: terpatwork | last post by:
Hi, (1) I have an access form that allows users to enter data, and when they click a button, the OnClick code that I've written uses a SQL INSERT statement to insert the data into the database. I...
3
by: Seong-Kook Shin | last post by:
C FAQ Q 13.2 says that sprintf() is guaranteed to work only for n <= 509: sprintf(dest, "%.*s", n, source); Does 509 appear in any C standard? If not, where it came from? I looked over C99...
2
by: Joseph Geretz | last post by:
I'm developing a Web Service using DIME to download and upload files from and to an IIS server. In order to increase the download filesize to unlimited, I have the following block in my App.config...
3
by: SDRoy | last post by:
Hi Is there a limitation on how many rows can be fetched using a SqlDataReader in ASP.Net 2.0 ? -- Thanks, SDRoy
4
by: Ole Nielsby | last post by:
Here comes a generic class with a static property. Let's say they are exotic singleton pets. abstract class Pet {...} abstract class SharedPet<T>: Pet where T: SharedPet<T>, new() {...
6
by: AB | last post by:
Hello all, I heard once that there is a limitation on the number of lines of code that a program can have when using C, but not for C++. Is this true? Any ideas?
1
by: =?Utf-8?B?UmFzaGVlZA==?= | last post by:
We have distributed application built upon .NET 2.0. The business components are exposed as Web Services. Some of the Business Components involves in heavy processing and occupies more RAM. It...
2
by: fdcm | last post by:
Hi, I am new to Access 2003 on XP. I am creating a database from a current report that has exceeded Excel 2003's row limitation. My concern is running into an Access limitation after creating the...
4
by: leegold58 | last post by:
Hi, Is there a "way around" the size limitation for Access? I'm thinking of something like spanning a huge table accross multiple databases... Something simple and that would preserve the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.