32-bit unsigned integers?

This is a discussion on 32-bit unsigned integers? within the C Programming forums, part of the General Programming Boards category; What does this mean and how do I declare an array that holds 32-bit unsigned integer in C?...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    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,046
    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, 07:02 PM
  5. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 06:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21