Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Data Structures - Retired Getting There The Beginning Bits

Craig's '14' Example

Why is there a '1' in the left-most digit of Craig's example.

Why doesn't that activate some extremely large number?

Thanks!

8 Answers

The leftmost bit only determines the sign of the integer. By the way, the number being positive 14, I think the leftmost bit shouldn't be a 1, so that might be a mistake. Maybe Craig Dennis can clarify.

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Whoa sorry everyone I just got tagged on this! Yes there is an error you are right! I will get it added to the teacher's notes. The MSB (most significant bit) should be 0 not 1. 1 is used to denote negative.

FYI, Craig Dennis ~ the Teacher's Note never made its way into the Teacher's Note section of this video. :-(

Yes can anyone clarify I thought everything was assumed positive, but if a value is negative how will it be identified?

Hi Shelman - As I mentioned above, the most significant, leftmost, bit is used to signify the sign of the integer. If that bit is is 0 then the number is positive. If that bit is 1 the number is negative. This method of representing integers in binary is called Signed magnitude. There are other methods of representing numbers in binary. Take a look at this page: https://en.wikipedia.org/wiki/Signed_number_representations#Signed_magnitude_representation

Hope this helps.

I was wondering the same thing, assuming the integer was signed i would've assumed it to be a negative number, and assuming Java uses two's complement a very high (or low, depending on how you look at it) negative number.

As the binary representation of the negative number, the MSB should be 1. But, the example in video is 14(positive number) so the MSB should be 0. Could you please confirm and update it?

I think that we are correct. The example is wrong? I don't really know hahaha.

having the same issue, is the example wrong or? Craig Dennis could you please share your knowledge?

Craig has stated in this thread that the left most number should be 0 not 1. It was a mistake in the video.

I'm curious of another aspect of the binary system. It starts at 2^0 and continues 2^1 which would be 0 and 2 respectively, correct? Surely, binary is not incapable of representing odd numbers? How would a 1 be represented?

2^0 actually equals one, not zero. Zero is the same as in decimal: 0.

%0000 = 0
%0001 = 1
%0010 = 2
%0011 = 3
%0100 = 4
%0101 = 5
%0110 = 6

etc.

For -14 not only MSB must be 1; -14 = 11111111111111111111111111111100 14 = 100 So, -14 + 14 = 0 And 11111111111111111111111111111100 + 100 = 0