Thread: 32-bit unsigned integers?

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    145

    32-bit unsigned integers?

    What does this mean and how do I declare an array that holds 32-bit unsigned integer in C?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    unsigned long int foo;

    This should be at least 32 bits.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    145
    What makes an unsigned int any different from a normal int?

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    201
    That is all explained in every C book there is....or else theres tons of articles about it on the net

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    145
    So unsigned only allows positive numbers?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    unsigned numbers are cryptographically insecure versions of signed numbers
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by Salem
    unsigned numbers are cryptographically insecure versions of signed numbers
    Ha ha!

    Basically, let's say you have an 8-bit int. On most computers one of the bits keeps track of the sign: 01100101. If the bold bit is 1 the number is negative, otherwise it's positive. Unsigned ints don't do this.
    If you understand what you're doing, you're not learning anything.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Since unsigned variables only allow whole numbers (positive (natural) numbers and zero), the extra bit that in signed numbers indicates the sign is part of the number. This means that you can numbers about twice as large in unsigned variables. eg
    Code:
    unsigned char: 0 - 255
    signed char: -127 -  127
    unsigned short: 0 - 65535
    signed short: -32767 - 32767
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bit level permutation function
    By zxcv in forum C Programming
    Replies: 2
    Last Post: 07-27-2008, 01:26 PM
  2. DrawIndexedPrimitive() Failing (DX9)
    By Epo in forum Game Programming
    Replies: 15
    Last Post: 09-24-2005, 03:32 PM
  3. porting application from 32 bit to 64 bit error
    By gandalf_bar in forum Linux Programming
    Replies: 1
    Last Post: 09-14-2005, 09:20 AM
  4. Porting from 32 bit machine to 64 bit machine!
    By anoopks in forum C Programming
    Replies: 10
    Last Post: 02-25-2005, 08:02 PM
  5. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 07:18 AM