This week's book giveaways are in the AI and JavaScript forums.We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Bear Bibeault
• Paul Clapham
• Jeanne Boyarsky
• Knute Snortum
Sheriffs:
• Liutauras Vilda
• Tim Cooke
• Junilu Lacar
Saloon Keepers:
• Ron McLeod
• Stephan van Hulst
• Tim Moores
• Tim Holloway
• Carey Brown
Bartenders:
• Joe Ess
• salvin francis
• fred rosenberger

# byte size and range

Greenhorn
Posts: 3
This is confusing me so any help explaining this would be helpful.
1)
a byte has 8 bits of storage. The MSB is the left bit and 1 indicates negative and 0 indicates positive.
2)
byte range is -128 to 127.
Since there are only 7 bits of storage(as 1 bit is used for the sign) how does it store -128?
e.g., 01111111 is 127
and 11111111 is -127
in binary 128 is 10000000 (so how can a byte hold -128?
Andy

Bartender
Posts: 2205
11111111 = -1 actually.
01111111 = 127
10000000 = -128

Ranch Hand
Posts: 165
In a byte if you don't have a sign bit then,
128 = 10000000
So lets see how to get -128 from this:
1. First invert/complement the bits: 01111111
2. Then add 1 to it: 10000000
So, this represents -128 in two's complement form.
With the first bit indicating the sign bit.
Until and unless I have forgotten the principles of digital logic that I learnt 12 years ago ...

Andy Jenks
Greenhorn
Posts: 3
Thanks robs its Twos complement then right
ie: I got this for how to calculate negative binaries
Thanks
Andy

How to find the Twos Complement of a number: A Quick Method
Suppose we want to find the twos complement 6-bit representation of -14
(1.) First, we write down the positive binary number, in this case 14
14 - 001110
(2.) Now, start writing the digits from the right hand side up to and including
the first 1. In our case, just 10.
(3.) Then invert the rest of the digits. So our answer becomes 110010. That's all!

Ranch Hand
Posts: 102
Two's complement representation of some bits to clarify! To get a negative number representaion,invert the bits of the corresponding number and add 1.
0 = 0000 0000
1 = 0000 0001 <---> -1 = 1111 1111
2 = 0000 0010 <---> -2 = 1111 1110
3 = 0000 0011 <---> -3 = 1111 1101
4 = 0000 0100 <---> -4 = 1111 1100
.
.
.
127 = 0111 1111 <---> -127 = 1000 0001
128 = 1000 0000 <---> -128 = 1000 0000
So, it all fits into 8 bits!
[ February 22, 2002: Message edited by: Jennifer Wallace ]

 Every plan is a little cooler if you have a blimp. And a tiny ad. Java file APIs (DOC, XLS, PDF, and many more) https://products.aspose.com/total/java