Re: Integer Division on 32 Bit Machines

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On Wed, Sep 8, 2010 at 8:40 AM, DG <dangets@xxxxxxxxx> wrote:


On Wed, Sep 8, 2010 at 12:51 AM, Bond <jamesbond.2k.g@xxxxxxxxx> wrote:


On Tue, Sep 7, 2010 at 11:14 PM, Bond <jamesbond.2k.g@xxxxxxxxx> wrote:


On Tue, Sep 7, 2010 at 3:32 PM, Andreas Leppert <wudmx@xxxxxx> wrote:
Hello,

I have encountered a problem on my 32 bit machine. Here some code
snippets:

typedef signed long s64;
Ok here is an article which cleared my doubts
but I am not clear with meaning of signed and unsigned.

Quick explanation/example:

With 8 bits you can represent (2 ** 8) -1 possible numbers.  Unsigned numbers mean that the number cannot be negative so the numbers go from 0 -> 255 (0b0000 0000 -> 0b1111 1111)  Signed numbers _can_ be negative so they represent the numbers in the range -128 -> 127 (0b1000 0000 -> 0b0111 1111)

The same thing applies to 32 bit integers.  Both signed and unsigned use the same number of bits, but they represent different ranges of numbers.  If your number is never expected to be negative, unsigned numbers give you a higher positive range.

To understand the negative numbering:
http://en.wikipedia.org/wiki/Twos_complement


Whoops, I meant to say:
with 8 bits you can represent 2 ** 8 (256) different numbers.  Unsigned numbers go from 0 -> (2 ** 8) -1

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux