Get the App
SLTechnology News&Howtos  ›  Development  › 

How to convert positive integers to negative ones by php

Shulou Source: shulou.com Published: 2022-06-03 11:37:16 10月03日 Update

Xiaobian to share with you how php positive integers into negative numbers, I believe most people do not know how to share this article for your reference, I hope you have a lot of harvest after reading this article, let us go to understand it together!

Php The method of converting an integer to a negative number: 1. Multiply a positive integer by negative 1, syntax "$num*(-1)";2. Use the "~" bit operator to reverse the positive integer and add one, you can get the complement of the negative number, syntax "~$num + 1".

Operating environment of this tutorial: Windows 7 system, PHP 7.1 version, DELL G3 computer

php converts positive integers to negative numbers

The first way (supporting decimals)

Output:

The second way (decimals not supported)

Output:

The negative number is stored in memory in the form of complement, and the complement is converted to the original code, which is the corresponding negative number after being converted.

Negative numbers are inverted and added to one to get a complement, but the complement of positive numbers is the same as the original code.

Note: negation and negation are two different concepts. Both operations are complementary forms participating in operations because negative numbers participate.

The above is "php how to turn positive integers into negative" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Tags: Negative numbers complements integers positive numbers articles plus one operation content decimal that is form mode syntax support output different not much two memory inverse code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Huawei MySQL Xiaomi Redmi