Problem with decimal to binary conversion
3 views (last 30 days)
I am using dec2bin() to convert '87' to its binary value. The function is returning '01010111'. I can't understand this output since '0101' is 5 in decimal and '0111' is 7. The output I was expecting was '10000111'.
On the other hand, if I convert just '8' to binary then the output is '1000'. Can someone please explain where I am wrong in my understanding?
Image Analyst on 7 Feb 2017
Why were you expecting that? Why should it give the binary representation for 135 = 2^7 + 2^2 + 2^1 + 2^0 instead of the binary representation for 87 like you asked for?