This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes negative numbers-2 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "negative numbers-2" Watch "negative numbers-2" New topic
Author

negative numbers-2

Gautam Sewani
Ranch Hand

Joined: Apr 19, 2002
Posts: 93
If I am giving the following number in Binary,and have to convert it to decimal,then what is the method for it?
11000111
Jamal Hasanov
Ranch Hand

Joined: Jan 08, 2002
Posts: 411
1[B] 1 0 0 0 1 1 1
7 6 5 4 3 2 1 0
1*2^7+1*2^6+0*2^5+0*2^4+0*2^3+1*2^2+1*2^1+1*2^0=
128+64+0+0+0+4+2+1=199
Best regards,
Jamal Hasanov
www.j-think.com
Jamal Hasanov
Ranch Hand

Joined: Jan 08, 2002
Posts: 411
1 1 0 0 0 1[B] [B]1 1
7 6 5 4 3 2 1 0
1*2^7+1*2^6+0*2^5+0*2^4+0*2^3+1*2^2+1*2^1+1*2^0=
128+64+0+0+0+4+2+1=199
Best regards,
Jamal Hasanov
www.j-think.com
Jamal Hasanov
Ranch Hand

Joined: Jan 08, 2002
Posts: 411
Please ignore previous posts - Some errors
1 1 0 0 0 1 1 1
7 6 5 4 3 2 1 0
Easy method :
If first digit is 1 (and size is maximal, for example: 8 in byte,16 in word,etc)
-(1*2^7+1*2^6+0*2^5+0*2^4+0*2^3+1*2^2+1*2^1+1*2^0)=
128-64-0-0-0-4-2-1=-57
Best regards,
Jamal Hasanov
www.j-think.com
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: negative numbers-2