Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!

# negative numbers-2

Gautam Sewani
Ranch Hand
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
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
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
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

 Consider Paul's rocket mass heater.