memory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arunraj2002in
    New Member
    • Jun 2007
    • 22

    memory

    Hi All,

    [CODE=c]int x;
    scanf("%x",&x);
    printf("%d",x);[/CODE]



    If user gives the i/p as FFFFFF00 what is the o/p?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by arunraj2002in
    Hi All,

    int x;

    scanf("%x",&x);

    printf("%d",x);



    If user gives the i/p as FFFFFF00 what is the o/p?
    If shows the decimal represenation of 0xffffff00 and it depends on the size of
    the ints on your computer. Why don't you give it a try?

    kind regards,

    Jos

    Comment

    • arunraj2002in
      New Member
      • Jun 2007
      • 22

      #3
      Originally posted by JosAH
      If shows the decimal represenation of 0xffffff00 and it depends on the size of
      the ints on your computer. Why don't you give it a try?

      kind regards,

      Jos

      Here the output is -256.. i don't understand why??

      Comment

      • arunraj2002in
        New Member
        • Jun 2007
        • 22

        #4
        Originally posted by arunraj2002in
        Here the output is -256.. i don't understand why??
        for input as 'ffffffff' the output is -1.. thats fine but why -256 for ffffff00

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by arunraj2002in
          for input as 'ffffffff' the output is -1.. thats fine but why -256 for ffffff00
          It's twos complement notation: if ffffffff equals -1, then fffffffe equals -2, then
          ffffffd equals -3, then ... then ffffff01 equals -255, then ffffff00 equals -256.

          kind regards,

          Jos

          Comment

          Working...