Java Foundation The second day _ binary conversion principle and complement storage method

Source: Internet
Author: User

1. What is the representation of negative numbers and why is it so designed?


A negative number is represented by a positive inverse plus one. The principle is that the sum of positive and negative numbers is 0. When the design plus and minus values are added, the first 1 will overflow due to exceeding the presentation range. Get the correct values for the complement notation.

For example, the number of binary representations of byte type, 0001 + 0111 1111 = (byte type is 8 bits, the 9th bit is 1 over range) 1 0000 0000, so take the front 8 bits, 0000 0000, the value is 0.

--------------------------------------------------

How is 2.-128 stored in memory? The calculation process?


128 in a 8-bit byte storage structure =1000 0000, in complement notation, 1000 0000 of the complement is also 1000 0000, because its sign bit is 1, which represents a negative number it represents-128.

If you calculate-128 by 127-1, the process is as follows

+127=0111 1111,-127=1000 0001,-128=-127-1=1000 0000

-------------------------------------------------

3. If the byte is represented as 11111111, what is its true data?


From the sign bit this is a negative number, first get its positive number. 1111 1111 of the inverse plus 1 is 0000 0001, the real data is +1


--------------------------------------------------

4. Do positive and negative numbers support the complement approach?


Positive and negative numbers support the complement approach


---------------------------------------------------

5. Is the positive number minus one negation?

Yes, 127=0111 1111=~ (+ 0001-1) =~1000 0000= 0111 1111

126=0111 1110=~ (+ 0010-1) =~1000 0001=0111 1110

125=0111 1101=~ (+ 0011-1) =~1000 0010=0111 1101



Java Foundation The second day _ binary conversion principle and complement storage method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.