Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


jon kelson
jon kelson
5,149 Points

Do you know the difference between Do you know the difference between signed and unsigned integers?

Do you know the difference between signed and unsigned integers? Please

2 Answers

Matthew Young
Matthew Young
5,133 Points

An unsigned integer is an integer that can only be positive. This is because it isn't represented with any sign in front of the number. Therefore, it can't have a minus sign in front of the number (hence, unsigned).

A signed integer is an integer that can be either positive or negative. That's because it can have a sign to represent whether the number is positive or negative.

For example, let's say you have an 8-bit integer. Computers use binary so you can only represent a binary number within those 8 bits as either 1 or 0. An 8-bit integer essentially only has 8 spots to place either a 1 or 0. Therefore, that means it can only have 256 unique combinations to be represented for decimal numbers. If it is unsigned, you can allocate all those combinations to be just a positive decimal number so you can have a number between 0 and 255 (including said numbers as well). If the integer is signed, you would have to allocate a portion of those 256 combinations to representing a negative decimal number. Therefore, the range becomes -128 to 127.

Depending on what application you're using the value for, you might want to get the highest possible value or have the ability to use negative numbers.

Benjamin PAYEN
Benjamin PAYEN
6,559 Points

With signed integers you can use negative values whereas with unsigned integers you can't. With a 16-bits signed integer you have a range of values between -32768 and +32768 whereas with an 16-bits unsigned integer you have a range of values between 0 and +65536.