Thread: 0xFFFFFFF7 = -9?

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    69

    0xFFFFFFF7 = -9?

    I feel stupid asking this question, but I'm obviously stumped by this one and I figured there was no better place to get an answer than here.

    Why does the code printf("%d\n", 0xFFFFFFF7); output -9? On a 32 bit system, this should result in a positive integer, right?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It depends on whether the number is signed or not. When you use "%d", it means that the value is seen as signed, which in turn means that you get -9, not a large positive number.

    If you use "%u", the number will be interpreted as a unsigned number, and thus will be a large positive number.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    69
    Thanks, Mats!

Popular pages Recent additions subscribe to a feed