c c complement shift, c complement arithmetic

Updated on technology 2024-02-09
5 answers
  1. Anonymous users2024-02-06

    int a is a signed number; Depending on the compiler, it may be 2-byte encoding (short int) or 4-byte (long int);

    Take a 2-byte encoding as an example: 10 = 0000 0000 0000 1010b (Note 1); It's an inverted code (bitwise), so.

    10 = 1111 1111 1111 0101b So 10+1 = 1111 1111 1111 0110b (Note 2) This happens to be the complement representation of -10, so the output is -10;

    To verify this problem, you can add the encodings of 10 and -10 above (annotations 1 and 2, respectively). In the case where the length of the word is determined, after adding, the carry of the highest digit is "naturally" lost, so that the result is 0.

    Complement is actually a pair of non-0 numbers that are allowed to be added to a finite word length, and their sum is 0. A logarithm that satisfies this condition is the opposite of each other under the condition of finite word length.

  2. Anonymous users2024-02-05

    The algorithm of the complement is to negate bitwise and then +1, and then inside the computer, the negative number is stored according to the complement, so you negate 10 bitwise, and then +1 is of course the complement of -10.

  3. Anonymous users2024-02-04

    In a computer system, numerical values are expressed in binary form.

    1, is 0000 0001. 1, then 1111 1111. If you want to change the symbol of the number to "opposite number", you can do the following:

    -x = ~x + 1After the operation, if the original number is 10, the result is 10.

    If the original number is 10, you get 10.

    This algorithm is based on the characteristics of the binary number system.

    This algorithm has nothing to do with finding the complement: "the original code is taken and the original code is added to the sign bit unchanged".

  4. Anonymous users2024-02-03

    1.Why use the original code, reverse code, and complement code.

    1) How do you represent negative binary?

    Answer: In the original code, a high position of 1 indicates a negative number.

    2) How does a computer implement subtraction?

    Answer: For computers, logical operations should be designed simply, 1-1 can be expressed as 1 + (-1), so there is no subtraction, and subtraction is achieved by addition.

    00000001] Original.

    10000001] Original.

    10000010] Original.

    If you use the original code and let the sign bits also participate in the calculation, it is obvious that the result is incorrect for subtraction. That's why the computer doesn't use the source code to represent a number.

    In order to solve the problem of subtraction of the original code, there is an inverse code:

    Expressions for calculating decimal systems:

    0001] original.

    0001] original.

    0001] anti.

    1110] anti.

    1111] anti.

    0000].

    3) How to represent the binary of 0, is there a difference between +0 and -0?

    Answer: +0 and -0, but the complement is 0, and the complement is used in the computer, so there is no distinction between +0 and -0 in the computer.

    Reason: The original code of 0, the reverse code, and the complement code are all 000000000

    The original code of 0 is 100000000, and the reverse code is 11111111

    And the complement is 00000000

    Complement solves two encoding problems for the symbol of 0:

    0001] original.

    0001] original.

    0001] supplement.

    1111] supplement.

    0000] complement = [0000

    0000] original = 0

    4) What is the original code of 8-bit, -128?

    Answer: -128 does not have the original code, the original code is expressed in the range of [-127,127], and the computer uses the complement code to represent it, because -0,1000 is removed

    0000] supplement.

    It's -128

    It can be used to represent the minimum value of -128, and the range of the complement is [-128,127].

    2.Why shifting left is a logical operation and shifting right is an arithmetic operation.

    Shifting left is a logical operation, and shifting right is an arithmetic operation.

    The logical shift is operated in conjunction with the flag bits (plus and minus signs), so it is possible to change the plus and minus signs.

    The arithmetic shift is to fix the flag bit, move the other bits, will not change the plus or minus signs, but the previous move is to make up 0 or 1, if the flag is 1, then all make up 1, if it is 0, then all make up 0.

    Answer: If the negative number is shifted to the right to make up 0, one is that the negative number becomes a positive number, and the number is 1, because the computer is a complement representation, because it is just right.

    3.Left shift is equal to *2, right shift is equal to 2, is it also suitable for negative numbers.

    Answer: Yes, the original misunderstanding is wrong, because it is considered from the perspective of the original code, not from the perspective of complement, and the computer uses the complement for calculation. The base number of the output is also a complement.

    In this example, int is 32 bits, 4 bytes, so there are 8 bits in hexadecimal.

  5. Anonymous users2024-02-02

    The article says that when eof, get will return 11111111111111111111111111111111, and if you assign a value directly to char, it will be truncated to 11111111.

    If char is unsigned, it becomes 2 32-1 compared to 2 8-1 and it is not equal.

    If the char is signed, it is more likely to be successful. Because at this time, the sign bit expansion will occur when the type is promoted, and all the 11111111 will be added in front of it.

    However, if there is a 11111111 character in the file, get will return a 00000000000000000000000011111111 and assign a value to char, which will still be truncated to 11111111. This results in an early end to the read.

    So you need to give an int first, 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 Assign it to char and you will be able to read the character 11111111.

    As for your question, I don't understand what it means to be a "complement".

Related questions
4 answers2024-02-09

Some of the relationships are syntactic and similar: the C language is closer to the underlying C++ is an extension of C, and the mechanism of the class is added; C is a step further than C++ is Microsoft's. The language in which .net is adopted. >>>More

7 answers2024-02-09

FIFA Online3 cc cards for Real Madrid are: Cristiano Ronaldo, Raul, Kaka, Cassie, Ramos, Carlos, etc. >>>More

14 answers2024-02-09

I think it's okay, now the system is mostly written in C, but it may be written in C at the beginning, and then the system is bigger, it is difficult to change it to C++, because the system is relatively large, so I think it is good to write in C++, easy to control, of course, the speed is to be discounted, but stability and flexibility should be more important, after all, the slow is better than the unmodifiable and the old crash, and the speed of C++ is not much worse than C, and even faster in some places, because now C++ development is much faster than CAs Bjarne Stroustrup said, learning C is just about dealing with the ** that is being taken as a legacy, hehe. I wonder if that's a bit too much? >>>More

10 answers2024-02-09

Frequent freezes, frequent blue screens, should be a hardware issue. >>>More

8 answers2024-02-09

Tell Lulouch his real name: Season 11

Shot by the Madness: Season 15 >>>More