In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article is a detailed introduction to "how to express signed and unsigned numbers in C language". The content is detailed, the steps are clear, and the details are properly handled. I hope this article "how to express signed and unsigned numbers in C language" can help you solve your doubts. Let's go deeper and learn new knowledge together with the ideas of Xiaobian.
1. Symbol bits in computers
A symbol used to identify data in the most significant bits of a data type.
The highest digit is 1, indicating that the number is negative.
The highest digit is 0, indicating that the number is positive.
Here's a code to determine the sign of the data:
#include int main(){ char c = -5; short s = 6; int i = -7; printf("%d\n", ( (c & 0x80) != 0 )); printf("%d\n", ( (s & 0x8000) != 0 )); printf("%d\n", ( (i & 0x80000000) != 0 )); return 0;}
The output is as follows:
The core idea of this code is to determine whether the highest bit is 1, and then do logical operations, if it is 1, then the operation is 1, otherwise it is 0.
II. Representation of signed numbers
Complements represent signed numbers inside a computer
The complement of a positive number is the positive number itself.
The complement of a negative number is the absolute value of a negative number.
For example:
8-bit integer 5 's complement is: 0000 0101
8-bit integer-7 complement is: 11111001
16-bit integer 20 's complement is: 0000 0000 0001 0100
16-bit integer- 13 complement is: 1111 1111 1111 0011
3. Representation of unsigned numbers
Unsigned numbers are represented internally by primitive codes
unsigned number defaults to positive
unsigned number has no sign bit
For unsigned numbers of fixed length
MAX_VALUE + 1 --> MIN_VALUE
MIN_VALUE - 1 --> MAX_VALUE
Signed and unsigned
C variables default to signed types
unsigned keyword declares variables to be unsigned types
Note: Only integer types in C can declare unsigned variables.
Here's a code for unsigned numbers meeting signed numbers:
#include int main(){ unsigned int i = 5; int j = -10; if( (i + j) > 0 ) { printf("i + j > 0\n"); } else { printf("i + j
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.