question

This is a discussion on question within the C Programming forums, part of the General Programming Boards category; i just wanted to ask whats the unsinged char and int ? and DWORD becasue i didnt see any tutrial ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    183

    question

    i just wanted to ask whats the unsinged char and int ? and DWORD
    becasue i didnt see any tutrial that talk abt them :S

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,734
    The unsigned means that the type has a non-negative range but same size and alignment requirements as the corresponding signed type (i.e., signed char and int in this case). For DWORD, read MSDN.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by lolguy View Post
    whats the unsinging char and int ?
    The unsinging character is mute.

    Just kidding! "unsigned" means it has no positive or negative sign (which means it is always a positive number). Without the sign, you have an extra bit to use as part of the stored value. Everytime you add a bit you double the possible range of values, so while a normal char can be from 0 to 127 (7 bits) with the sign (- or +), an unsigned char is a full 8-bit number, 0-255, but it cannot be set negative.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    what about unsinged char ? how will it non nagative and its just a char? ?

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,734
    Quote Originally Posted by MK27
    so while a normal char can be from 0 to 127 (7 bits) with the sign (- or +)
    That would be the case for sign and magnitude and one's complement, but with two's complement the range of an 8-bit signed char would be [-128,127]. Also, it is implementation defined whether char is signed or unsigned.

    Quote Originally Posted by lolguy
    what about unsinged char ? how will it non nagative and its just a char? ?
    You might want to rephrase that using proper English. I am afraid that I do not understand your question considering what MK27 and I have stated.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by lolguy View Post
    what about unsinged char ? how will it non nagative and its just a char? ?
    The unsinged character avoids open flame. Ha ha ha again! Don't even ask about the unhinged char.

    A char is a value. These values translate to alphanumeric symbols when you use printf, etc. Have a look at the ASCII table. So for example:
    Code:
    char X='X';
    char X=88;
    are exactly the same thing. The first form is for convience.
    Quote Originally Posted by laserlight
    with two's complement the range of an 8-bit signed char would be [-128,127]. Also, it is implementation defined whether char is signed or unsigned.
    I did not know this -- I suppose that's because we don't need a "-0"?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #7
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    oh thanks alot i understand it now

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,734
    Quote Originally Posted by MK27
    I did not know this -- I suppose that's because we don't need a "-0"?
    I am not sure if we can consider the lack of a negative zero as the reason (perhaps the fact that the sign bit has a -(2^N) value instead of -(2^N - 1) value is the reason), but either way it is the way the mathematics works out.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by laserlight View Post
    it is the way the mathematics works out.
    Hey look my 666th post!

    That the sign is the first bit and that if set the remaining bits are flipped I can understand. If this is the math:
    Quote Originally Posted by Wikipedia, the free encyclopedia

    The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of two and adding 1(specifically, from 2N for an N-bit two's complement).
    then I don't quite get it: wouldn't that mean if the number is 1000001, the number should be 128-1+1=128, when actually 10000001 is -127. And 10000000 (-128) would be 128-0+1=129?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,734
    Quote Originally Posted by MK27
    then I don't quite get it: wouldn't that mean if the number is 1000001, the number should be 128-1+1=128, when actually 10000001 is -127.
    Since the most significant bit is negative, it should be: -128 + 0 + ... + 0 + 1 = -127.

    Quote Originally Posted by MK27
    And 10000000 (-128) would be 128-0+1=129?
    Why do you add the 1 when all the remaining bits are unset?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by laserlight View Post
    Why do you add the 1 when all the remaining bits are unset?
    Is this definition wrong then?
    subtracting the number from a large power of two and adding 1
    Again, flipping the bits makes sense (I imagine this is what really happens) but this math formula is what looks unsinged to me. Altho either way I can't find -128 unless it is just treated as a special case, 10000000, which would have been 128 unsigned.

    The only way I can see to describe this is to simply say 2N-value*sign, which will invariably work. I assume that the computer does not really use these silly formulas anyway -- Math people are ridiculous
    Last edited by MK27; 01-18-2009 at 10:07 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,734
    Quote Originally Posted by MK27
    Is this definition wrong then?
    Probably: take a look at the "Calculating two's complement" of the same article where it gives a correct formula without the addition of 1.

    EDIT:
    Quote Originally Posted by MK27
    The only way I can see to describe this is to simply say 2N-value*sign, which will invariably work.
    There is no need to multiply by a sign value because the operation is performed with a fixed number of bits.
    Last edited by laserlight; 01-18-2009 at 10:17 AM.

  13. #13
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by laserlight View Post
    Probably: take a look at the "Calculating two's complement" of the same article where it gives a correct formula without the addition of 1.
    Okay, cool, I thought that was my math ignorance at work.

    Quote Originally Posted by wikipedia
    The value of a two's-complement binary number can be calculated by adding up the power-of-two weights of the "one" bits, but with a negative weight for the most significant (sign) bit
    Makes sense and it is different than 2N-value+1.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

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