Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the binary representation of negative numbers

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "what is the binary representation of negative numbers". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Source code: an integer that is converted into a binary number according to the size of the absolute value, called the original code.

For example, 00000000 00000000 00000000 00000101 is the original code of 5.

Inverse code: the binary number is reversed bit by bit, and the resulting new binary number is called the inverse code of the original binary number.

The reverse operation refers to: the original is 1, get 0; the original is 0, get 1. (1 to 0; 0 to 1)

For example, if you reverse each of 00000000 00000000 00000000 00000101, you will get 11111111111111111111111010.

It says: 11111111 11111111 11111111 11111010 is the inverse of 0000000000000000000000101.

Anti-codes are mutual, so they can also be called:

11111111 11111111 11111111 11111010 and 000000000000000000000101 are opposite codes to each other.

Complement: adding 1 to an inverse code is called a complement.

In other words, to get the complement of a number, you first get the inverse code, and then add the inverse code to 1, and the resulting number is called the complement.

For example, the inverse code of 00000000 00000000 00000000 00000101 is 111111111111111111111111111010.

So, the complement is:

11111111 11111111 11111111 11111010 + 1 = 111111111111111111111111111011

Therefore,-5 is expressed in the computer as: 11111111 11111111 11111111 11111011. Convert to hexadecimal: 0xFFFFFFFB.

For another example, let's look at how integer-1 is represented in a computer.

Assuming that this is also an int type, then:

1. The original code of taking 1 first: 00000000 00000000 00000000 00000001

2. Reverse code: 11111111 11111111 11111111 11111110

3. Supplementary code: 11111111 11111111 11111111

It can be seen that the binary expression of-1 in the computer is all-1. Hexadecimal: 0xFFFFFF

This is the end of the content of "what is the binary representation of negative numbers". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report