Computer numerical calculations are all binary, but will different encodings generate different binary numbers?

WBOY
Release: 2016-08-04 09:20:10
Original
1257 people have browsed it

For example, when calculating 2*3, the computer will first convert it into binary for calculation. If it is a different encoding form, does it correspond to a different binary?

Reply content:

For example, when calculating 2*3, the computer will first convert it into binary for calculation. If it is a different encoding form, does it correspond to a different binary?

Yes, different encodings will have different methods of recording data, and of course they will also be similar.

Encoding mainly targets strings. Digital storage is also divided into big and small endian order, which are all manifestations of different binary data recording rules.


The questioner has several basic concepts that need to be clarified first.

First of all, what you are talking about should be "2*3" in the source code. The character encoding of the source code files can be different, and their binary representations are also different. Then you mentioned "calculation", which must first be compiled to generate target code before it can be executed (whether it is interpreted or executed by cpu instructions). If you generate machine code, then on the same machine, the format of digital storage it's the same. If it is the bytecode generated by a virtual machine, the number format is the same as the encoding of the bytecode.

You must first figure out the type of data. Your calculation of 2*3 is a calculation of two integers, which is 10*11 (binary). There is no encoding. If you put it on different architectures, it just means that the length of the integers is different.

The encoding you mentioned is for characters. For example, the ASCII of 2 and 3 are 0110010 and 0110011 respectively. This is not used for calculation.

Yes, you can use any encoding and store it however you want.

But the calculation results must be the same.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template