473,387 Members | 1,863 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,387 software developers and data experts.

How do computers do arithmatic?

Daz
Hi everyone.

I am a little confused and frustrated as to how the maximum lengths for
integers and floating point numbers came about, and whilst you
shouldn't need a number bigger than 2147483647, I am sure the need is
there.

Please could someone explain vaguely the key things that I should be
looking for as my Google searches don't tend to yield the answers to my
questions. I understand that it varies from one machine machine due to
the wordsize of that machine, but that's about all I do get. Why
couldn't integers be dynamic like strings? Why are they limited to 64
bits and floats (I think), 128 bits?

I am contemplating making a class that can handle numbers of almost
unlimited length, as I can't seem to see any online. Then again I
haven't looked very hard, as I only want to make this class to see if I
can do it, and to broaden my knowledge a little more. I think it's safe
to assume that there are plenty of people who have thought about this
besides me.

Your input would be much appreciated as always.

Jun 18 '06 #1
7 1524
"Daz" writes:
I am a little confused and frustrated as to how the maximum lengths for
integers and floating point numbers came about, and whilst you
shouldn't need a number bigger than 2147483647, I am sure the need is
there.

Please could someone explain vaguely the key things that I should be
looking for as my Google searches don't tend to yield the answers to my
questions. I understand that it varies from one machine machine due to
the wordsize of that machine, but that's about all I do get. Why
couldn't integers be dynamic like strings? Why are they limited to 64
bits and floats (I think), 128 bits?

I am contemplating making a class that can handle numbers of almost
unlimited length, as I can't seem to see any online. Then again I
haven't looked very hard, as I only want to make this class to see if I
can do it, and to broaden my knowledge a little more. I think it's safe
to assume that there are plenty of people who have thought about this
besides me.


Computers sold to compute, as opposed to embedded computers, are almost
always based on an eight-bit byte. Hardware and eight-bit bytes are a
comfortable match.

If I were to set out to do what you describe, I would use what is called BCD
(binary coded decimal) encoding. This eliminates some potentially nasty
conversions between binary and a decimal number that a human can deal with.
Each byte would contain only the values 0 through 9, and the sign of the
number would be maintained separately. You will need to know about carry in
and carry out. I think Wikipedia is the best place to start on this
problem.

This looks pretty good.

http://en.wikipedia.org/wiki/Binary-coded_decimal
Jun 18 '06 #2
"Daz" <cu********@gmail.com> wrote:
I am a little confused and frustrated as to how the maximum lengths for
integers and floating point numbers came about, and whilst you
shouldn't need a number bigger than 2147483647, I am sure the need is
there.
You are right that there are, on occasion, need for larger integers. A
common application today is cryptography, which uses very large integers
(over 100 digits, in some cases). There are multiple-precision (sometimes
called "bignum") libraries which allow you to do this. It's a lot slower
than fixed-length math, which is why it's not the default in most
languages. Some languages do have built-in bignum support:

Python 2.3.4 (#3, Jun 29 2004, 21:48:03)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
123456789 * 987654321 121932631112635269L

I am contemplating making a class that can handle numbers of almost
unlimited length, as I can't seem to see any online.
Search for "bignum" or "multiple precision", and you'll find plenty of them.
Then again I haven't looked very hard, as I only want to make this class
to see if I can do it, and to broaden my knowledge a little more.
This is indeed an excellent learning exercise. Go for it.
I think it's safe to assume that there are plenty of people who have
thought about this besides me.


This is certainly true, but there's no harm in you thinking about it too.
People are constantly looking at "solved problems" and finding better ways
to do it.

Here's a couple of good Wikipedia articles that you might find useful:

http://en.wikipedia.org/wiki/Arbitra...ion_arithmetic
http://en.wikipedia.org/wiki/IEEE_fl...point_standard
Jun 18 '06 #3
Hi Daz,
My project I'm working on is to make integers, a double linked bytes,
unlimited and I'm working on its mathematical operations like addition,
substraction...
It's called Multiple Byte integers.

Shuga.

Jun 18 '06 #4
Daz wrote:
Hi everyone.

I am a little confused and frustrated as to how the maximum lengths for
integers and floating point numbers came about, and whilst you shouldn't
need a number bigger than 2147483647, I am sure the need is there.
In the back of an elementary school math textbook, you may find a
"multiplication table". It lists the numbers from 1 to 10 at the heads of
columns and rows, and it shows the product of each row and column in a
cell. Here's its upper left corner:

1 2 3
+------
1 |1 2 3
2 |2 4 6
3 |3 6 9

To multiply, a computer draws one of those grids in hardware. The number 2
will relay into this grid, and latch (switch on) the horizontal 2 wire.
The number 3 then relays into the grid and latches the 3 wire, going down.
Where the wires cross, the 6 register receives a complete electrical
signal, and it latches a 6 output. Further relays (actually "gates") turn
the 6 wire into a binary 6, 0110, and this latches into the output
register.

The width of a CPU's internal bus determines the width of its grids in its
arithmetic logic unit. So an old 16-bit processor would have ALU grids
with 65,536 wires on each side.

That's why CPUs are so big and hot, and why math with numbers that fit in
a CPU's bus can arithmetic faster than larger numbers. They require small
subroutines to decompose the numbers first - like long multiplication.
I am contemplating making a class that can handle numbers of almost
unlimited length, as I can't seem to see any online.


There are zillions, all called "bigint", so Google that.

--
Phlip
Jun 18 '06 #5
Daz
Great links everyone.

I have no idea why I didn't think of looking at wikipedia in the first
place...

Thanks for such great input, as always. :)

Daz

Jun 18 '06 #6
Daz wrote:
Please could someone explain vaguely the key things that I should be
looking for as my Google searches don't tend to yield the answers to my
questions. I understand that it varies from one machine machine due to
the wordsize of that machine, but that's about all I do get. Why
couldn't integers be dynamic like strings?
They can, it's just that this is not commonly done in hardware.
Processors are much easier to design when the datatypes that they work
with are fixed-length records with a rigid structure. This is true of
the instruction opcodes also, not just the data types.

Note that dynamic strings are implemented by the run-time support of
your higher level programming language. Chances are that the processor
you are using has next to no support for strings.

Likewise "bignum" integers, are implemented in libraries. In some
programming languages, like Common Lisp, such numbers are built in,
seamlessly integrated with the type system of the ``numeric tower''.

It's unlikely that moving this functionality into the processor would
result in any kind of performance improvement. The processor would have
to implement the same algorithms as the library: basically treat the
big numbers as being made up of arrays of fixed-sized smaller numbers,
and use loops to perform the algorithms like addition, long division
and so on. These procedures would probably be written in microcode, and
occupy quite a lot of precious silicon on the processor chip.

On a modern, heavily cached processor, there isn't much difference
between a function that is written in software and a function that is
in microcode. The instructions are so simple to decode that they are
almost like microcode already, and sufficiently small sequences of code
can fit into the instruction cache entirely. Moreover, an instruction
cache can partially decode the instructions, so they resemble microcode
even more. E.g. say, a loop which adds or multiplies two bignum
integers will probably all fit into the instruction cache. The nice
thing about that is that when the algorithm is done, the cache can be
reused for something else. This is better use of silicon than
dedicating it to a library of microcode for complex operations that not
every application needs.
I am contemplating making a class that can handle numbers of almost
unlimited length, as I can't seem to see any online. Then again I
haven't looked very hard, as I only want to make this class to see if I
can do it, and to broaden my knowledge a little more. I think it's safe
to assume that there are plenty of people who have thought about this
besides me.


You think? Nah ... Only the brightest minds on the bleeding edge of
computer science research are just beginning to think about large
integers and their potential applications, such as public key
cryptography. :)

Jun 18 '06 #7

"osmium" <r1********@comcast.net> wrote in message
news:4f*************@individual.net...
"Daz" writes:
I am a little confused and frustrated as to how the maximum lengths for
integers and floating point numbers came about, and whilst you
shouldn't need a number bigger than 2147483647, I am sure the need is
there.

Please could someone explain vaguely the key things that I should be
looking for as my Google searches don't tend to yield the answers to my
questions. I understand that it varies from one machine machine due to
the wordsize of that machine, but that's about all I do get. Why
couldn't integers be dynamic like strings? Why are they limited to 64
bits and floats (I think), 128 bits?

I am contemplating making a class that can handle numbers of almost
unlimited length, as I can't seem to see any online. Then again I
haven't looked very hard, as I only want to make this class to see if I
can do it, and to broaden my knowledge a little more. I think it's safe
to assume that there are plenty of people who have thought about this
besides me.


Computers sold to compute, as opposed to embedded computers, are almost
always based on an eight-bit byte. Hardware and eight-bit bytes are a
comfortable match.

If I were to set out to do what you describe, I would use what is called
BCD (binary coded decimal) encoding. This eliminates some potentially
nasty conversions between binary and a decimal number that a human can
deal with. Each byte would contain only the values 0 through 9, and the
sign of the number would be maintained separately. You will need to know
about carry in and carry out. I think Wikipedia is the best place to
start on this problem.


Normally, in BCD each byte contains two digits. One digit in the lower
nibble (half a byte), one digit in the higher nibble.
Jun 19 '06 #8

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

Similar topics

2
by: Dannic | last post by:
Here is the application. Its a simple application really. I have a db created in Access 2000 which opens to a switchboard created by the switchboard manager. Now the problem. This only works...
10
by: MHenry | last post by:
Hi, We were going merrily along for 6 years using this database to record all client checks that came into our office, including information about what the checks were for. Suddenly, network...
8
by: Vanga Sasidhar | last post by:
I have four computers. One computer - Win XP Two computers - Win 98 One computer - Win ME I designed some pages in my computer having Win XP operating system. I installed dot net...
4
by: JB | last post by:
I am trying to get a list of all the active computers running on my domain. I'm writing some remote management style software with WMI, which works fine when i know the computer name, but i just...
2
by: sapnakiran | last post by:
Can u tell me how can we build up arithmatic operation without using arithmatic operator
17
by: John Salerno | last post by:
Let me see if this question even makes sense...I'm reading Core Python Programming and I jumped ahead to the more specific topics like network programming. I plan to follow along with the example...
8
Plater
by: Plater | last post by:
I hope I can explain this correctly. BACKGROUND: My office has a local network. We use a windows server 2003(small business server i think) computer to handle our domain. So all of our employees...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.