• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

confusion with primitives

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

why are the m and n values same??? though we have assigned a -m to n...

 
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try so see output of following code. You will get the reason.

 
saipavan vallabhaneni
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry Himanshu,
i didn't understand what you were trying to tell

1.4E-45 -1.4E-45
-2147483648 -2147483648
-1 1
integer max value: 2147483647

Output completed (0 sec consumed)


i got the following output...

why is n being assigned a -ve value where we assigned -m to n

 
Ranch Hand
Posts: 509
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, check compiling this code.



I think it will clear your doubt.
The Range of byte is -128 - 127.
So it cannot hold a value -b1 which is +128.
 
saipavan vallabhaneni
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks himanshu and abhi

i understood now
 
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The min value of any integer type is represented at the bit level by the fist bit (the sign bit) being one, and the rest of the bits being 0. This means that:

1000...00 // MIN_VALUE
0111...11 // MIN_VALUE 1's complement
1000...00 // MIN_VALUE 1's complement + 1 = MIN_VALUE 2's complement

So MIN_VALUE and -MIN_VALUE are always the same.

The same is obviously not the case of MAX_VALUE and -MAX_VALUE, since the bit patterns capable of representing negative integers is one more than those capable of representing strictly positive integers.

0111...11 // MAX VALUE
1000...00 // MAX VALUE 1's complement
1000...01 // MAX_VALUE 2's complement

In this case, negating MAX_VALUE will give you what you would expect from a mathematical point of view.
 
For my next trick, I'll need the help of a tiny ad ...
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic