Crazy guy c Study Notes (2)

Source: Internet
Author: User

Main content:

1. The computer indicates a negative number.

Original code representation: the highest digit represents the plus or minus sign, and the rest represents the value. 0 positive, 1 negative.

Reverse code representation: the representation of positive numbers is the same as that of the original code. For a negative number, the highest bit is recorded as 1, indicating that it is a negative number. In the value section, you are taken back, that is, 0 is written as 1, 1 is written as 0.

Complement representation: The most common representation method. The expression of positive numbers is the same as that of the preceding two methods. The negative expression is based on the reverse code representation plus 1. Another method to calculate the complement of a negative number is power (2, the number of digits of the machine) + this negative number.

How can I request a complete code? First, you need to know the number of digits of the machine, and then calculate according to the order of the original code --> reverse code --> complement code.

Look at my machine, printf ("% d \ n", (-123%-2); yes-1 Yeah ~

%, What is the modulo operation? How to deal with negative numbers? "On the premise that the number of integers for two int operations is rounded to 0, the notation of the result of the % operation is always the same as that of the divisor"

"Without a deep understanding of data types, you cannot really understand the C language"

2. Implement the power of 11 to 20 times of 2

# Include <stdio. h> # include <stdlib. h>/* calculate the power B of A */double power (int A, int B) {If (B = 0) {return 1.0;} if (a = 0) {return 0.0;} int temp = B> 0? B:-B; double result = 1.0; while (temp> 0) {result = Result * A; temp --;} If (B> 0) {return result ;} else {return 1.0/result ;}} int main () {double result; int I; for (I = 11; I <= 20; I ++) {result = power (2, I); printf ("% d power of 2 = % F \ n", I, result );}}

Result:

3. Int type

Int, equivalent to signed int, equivalent to signed. Range: int_min ~ Intmax, defined in limits. h file. Storage Space 4 bytes, 32bit

Unsigned Int. the bucket is the same as that of Int. The value range is 0 ~ Uint_max, 2 ^ 32, suffix U or U

Long, equivalent to long int, equivalent to signed long, signed long int, precision at least 32 bits

Unsigned long, equivalent to unsigned long int, unsigned long, the same number of digits as long, suffix Lu

Short, equivalent to short int, signed short int, with at least 16 bits

Long long, at least 64-bit

4. Char type

ASCII code, which contains 7 bits and a maximum of 128 characters. Among them, 96 are printable and 32 control characters are supported. Letter A: 65D; letter A: 97d; Case difference: 32d.

Char_bit is the length of the char type.

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.