Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

confused  RSS feed

 
zaghal mohd
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you pleas help me to understand this question?

-11 10
why its not 10 -10
thanks in advs......
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a program that I wrote this morning for the next version of my mock exam.

It prints true,true.
If you want to calculate the negative of any number in two's compliment format, then invert the bits and add one. The ~ operator inverts the bits.
 
zaghal mohd
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you dan you are doing well in your mock exams good luck and thanks again
zaghal
 
Charu Murali
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can easily remember the function of ~ operator as " ~X = (-X)-1 ". So in your question ~10 = (-10)-1 = -11.

HTH.
Charu
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!