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

How to convert negative numbers to positive integers by php

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how php turns negative numbers into positive integers". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how php turns negative numbers into positive integers".

Php turns negative numbers into positive integers: 1, use abs () function to turn negative numbers into positive numbers, use intval () function to round positive numbers and turn them into positive integers, syntax "intval (abs ($number))"; 2, use the "~" bit operator to add negative numbers to one, syntax "~ $number + 1".

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

The method of changing negative numbers into positive integers by php

Method 1: use the abs () and intval () functions

The abs () function turns a negative number into a positive number.

The intval () function is rounded to a positive integer.

Implementation code:

Method 2: use the "~" bit operator to reverse the negative number by one.

Description:

After the positive number is inverted by one, the complement of the negative number is obtained, and the negative number is stored in memory in the form of a complement, and the conversion of the complement to the original code is the corresponding negative number after the positive number is transformed.

When a negative number is inverted by one, you get a complement, but the original complement of a positive number is the same.

Note: inversion and inversion are two different concepts, and both take part in the operation in the form of complement, because negative numbers participate in the operation.

At this point, I believe you have a deeper understanding of "how php turns negative numbers into positive integers". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Development

Wechat

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

12
Report