[Tutor] difference between signed integers and unsigned integers

tpc at csua.berkeley.edu tpc at csua.berkeley.edu
Fri Jan 23 13:25:16 EST 2004


hi Hameed, I wanted to correct an erroneous statement I made before
about an unsigned data type having more combinations than a signed data
type.  That is untrue.  A signed data type will have the same range as an
unsigned data type because the signed data type has negative values as
well as positive, whereas the signed data type has only positive.
Let's say you have a 3 bit data type, one signed the other unsigned.
The possible combinations for this unsigned is 2^3 with a range of
0 to (2^3 - 1):

0, 1, 2, 3, 4, 5, 6, 7

while the possible combinations unsigned is also 2^3 with a range of -2^2
to 2^2:

-4, -3, -2, -1, 0, 1, 2, 3, 4

Sorry for the confusion.  I hope that helps you.

On Wed, 21 Jan 2004 tpc at csua.berkeley.edu wrote:

>
> hi Hameed,
>
> Signed integers have one bit allocated to indicate whether the value is
> positive or negative.  Unsigned integers do not.  The difference between
> them is in certain languages with data types of a specific size, an
> unsigned data type can hold more combinations than a signed value.  If
> you think of a byte as eight switches, each with the on or off showing,
> then a signed byte will have only 7 boxes to store values, as opposed to
> the unsigned byte which will have 8 boxes.
>
> I hope that helps you.
>
> On Wed, 21 Jan 2004, Hameed Khan wrote:
>
> > Hi,
> >   i know my question is not directly related to
> > python. but i just have started the programming in
> > python. so i am not a profesional programmer or an
> > expert. and i am only subscribed to the python's
> > mailing lists. thats why i am asking this question on
> > this list. i want to know what are signed and unsigned
> > integers and what is the difference between them.
> >
> > Thanks,
> > Hameed Khan
> >
> > =====
> > _____________________
> >  Hameed Ullah Khan
> >
> > *Try not to become a man of success but rather to become a man of value.*
> > Albert Einstein
> >
> > __________________________________
> > Do you Yahoo!?
> > Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
> > http://hotjobs.sweepstakes.yahoo.com/signingbonus
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>




More information about the Tutor mailing list