Computer composition principle

Source: Internet
Author: User

I: source code, complement code, and reverse code

 

1. In computer systems, all values are usedComplementTo store

The complement code can be used to process the symbol bit and other digits in a unified manner, and the subtraction can also be processed by addition.

The sum of the two numbers represented by the complement code is: if the highest bit (symbol bit) has an incoming bit, the carry is discarded.

2. The positive complement is the same as the original code.

3. complement a negative number: the sign bit is 1, and the rest is the original code, which is reversed by bit, then the entire number is + 1

4. Obtain the source code with known completion codes:

Negative Number: (symbol bit) is 1, and the rest are reversed, then the entire number is + 1

5. Model:

The counting range of a metering system. The Metering range of the clock is 0 ~ 11, modulo = 12

In essence, the metering device generates an "overflow" amount. Its value cannot be expressed by the metering device, and the metering device can only represent the remainder of the output mode.Any metered tool with modulus can be used as addition operations by subtraction.For example, if the current time is 6 points but the clock points to 10 points, you can change the value of 4 hours to 10-4 = 6. You can also set the value to 8 hours (10 + 8) % 12 = 6. For a modulo, 8 and 4 complement each other. The sum of the two equals to the modulo.

 

When Int32 a =-1 is converted to a string using the Convert. ToString () method, It will be converted to a 32-Bit String 11111111111111111111111111111111 which is still unknown here. Is the first digit followed by a negative number? Write a small item to verify it.

 

 

 Namespace SchedulerEngine
{
Public partial class MainPage: UserControl
{
Public MainPage ()
{
InitializeComponent ();

Int a =-12341;
String t = GetComplement ();

Debug. WriteLine (GetStOfInt (a *-1 ));

}

Public static string GetStOfInt (int _)
{
Return Convert. ToString (_ a, 2 );
}

Public static string GetStOfInt (long _)
{
Return Convert. ToString (_ a, 2 );
}


Public string GetComplement (int _)
{
Debug. WriteLine (GetStOfInt (_ ));
If (_ a> = 0)
{
Return Convert. ToString (_ a, 2 );
}
Else
{
// Obtain the number of digits with the same number, but the first digit (symbol bit) is 1 (negative), and the other digits are zero.
Int B = 1 <(Convert. ToString (_ a, 2). Length-1 );
Debug. WriteLine (GetStOfInt (B ));
// Subtract the two to get a number that removes the symbol bit
Int a = _ a-B;
Debug. WriteLine (GetStOfInt ());
// Obtain the original code by adding 1 to the backend.
Int c = ~ A; // This operation adds a bit. Why?
Debug. WriteLine (GetStOfInt (c ));
Int d = c + 1;
Debug. WriteLine (GetStOfInt (d ));
// Original code with a symbol bit
Return GetStOfInt (d );
}
}
}

 

 

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.