Table of Contents
php base and bit operations
Home Backend Development PHP Tutorial PHP base and bit operations_PHP tutorial

PHP base and bit operations_PHP tutorial

Jul 12, 2016 am 09:07 AM
base

php base and bit operations

//八进制 ,前面加0代表8进制
echo 0123 , &#39;<br/>&#39;; //十进制83 从右到左3个位,分别是以1顶1,以1顶8 ,以1顶64
echo 027 , &#39;<br/>&#39;;//23
 
//十六进制,前面加0x代表16进制 , 0 1 2 3 4 5 6 7 8 9 a b c d e f 
echo 0x123 , &#39;<br/>&#39;;//十六进制 从右到左3个位,分别是以1顶1,以1顶16 ,以1顶256
echo 0x27 ."<br>";
echo 0x1c ."<br>"; //28
 
//二进制 ,php目前不支持直接表示 ,从右到左,分别以1顶1,顶2,顶4,顶8.....
/*
10进制       2进制
5        0000 0101
255          1111 1111        
*/
 
//位运行符,&位与运算符 , | 位或运算符
echo 5&12 ,&#39;<br/>&#39;; //6
echo 5|12 ,&#39;<br/>&#39;; //13
 
echo 5^12 ,&#39;<br/>&#39;;//异或 9
 
echo ~5 ,&#39;<br/>&#39;;//取反
 
//利用位运算的左移一位,使整数增大2倍;相应得位运算的右移一位,使整数减小2倍
$a=3;
echo $a << 1 ,&#39;<br/>&#39;;//6
echo $a << 2 ,&#39;<br/>&#39;;//12
 
 
// 赋予权限值-->(删除:8)( 上传:4) (写入:2) (只读:1)
define(&ldquo;mDELETE&rdquo;,8);
define(&ldquo;mUPLOAD&rdquo;,4);
define(&ldquo;mWRITE&rdquo;,2);
define(&ldquo;mREAD&rdquo;,1);
 
//部门经理的权限为(假设它拥有此部门的所有权限)
echo mDELETE|mUPLOAD|mWRITE|mREAD // 相当于是把上面的权限值加起来:8+4+2+1=15
 
// 设我只有 upload 和 read 权限,则
echo mUPLOAD|mREAD
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1061304.htmlTechArticlephp Base and bit operations//Octal, add 0 in front to represent octal echo 0123, br/; / /Decimal 83 has 3 digits from right to left, 1 is used as 1, 1 is used as 8, and 1 is used as 64echo 027, br/;//23 //Hexadecimal...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Use the strconv.FormatInt function to convert an integer into a string in the specified base Use the strconv.FormatInt function to convert an integer into a string in the specified base Jul 24, 2023 am 10:51 AM

Use the strconv.FormatInt function to convert an integer into a string in a specified base. In the Go language, the strconv package is a commonly used package for converting between strings and other data types. The strconv.FormatInt function can convert an integer into a string in a specified base. This article will introduce the use of strconv.FormatInt and provide some sample code. First, let's take a look at strconv.FormatIn

Convert string to hexadecimal and achieve reverse output using PHP Convert string to hexadecimal and achieve reverse output using PHP Mar 21, 2024 pm 03:33 PM

Title: Use PHP to convert strings to hexadecimal and achieve reverse output. In daily development, we sometimes need to convert strings to hexadecimal representation for data transmission or encryption. This article will introduce how to use PHP to convert a string into hexadecimal and realize the reverse output function. First, we need to write a PHP function to convert a string to hexadecimal. The following is an example code: functionstringToHex($string)

How to solve the problem of Chinese garbled characters when converting hexadecimal to string in PHP How to solve the problem of Chinese garbled characters when converting hexadecimal to string in PHP Mar 04, 2024 am 09:36 AM

Methods to solve Chinese garbled characters when converting hexadecimal strings in PHP. In PHP programming, sometimes we encounter situations where we need to convert strings represented by hexadecimal into normal Chinese characters. However, in the process of this conversion, sometimes you will encounter the problem of Chinese garbled characters. This article will provide you with a method to solve the problem of Chinese garbled characters when converting hexadecimal to string in PHP, and give specific code examples. Use the hex2bin() function for hexadecimal conversion. PHP’s built-in hex2bin() function can convert 1

Easily learn to convert hexadecimal to binary in Go language Easily learn to convert hexadecimal to binary in Go language Mar 15, 2024 pm 04:45 PM

Title: Easily learn to convert hexadecimal to binary in Go language. Specific code examples are required. In computer programming, conversion operations between different base numbers are often involved. Among them, conversion between hexadecimal and binary is relatively common. In the Go language, we can achieve hexadecimal to binary conversion through some simple code examples. Let us learn together. First, let's take a look at the representation methods of hexadecimal and binary. Hexadecimal is a method of representing numbers, using 0-9 and A-F to represent 1

Convert string to hexadecimal and reverse output through PHP Convert string to hexadecimal and reverse output through PHP Mar 22, 2024 am 10:57 AM

Title: PHP converts a string to hexadecimal and reversely outputs it. In network programming, sometimes it is necessary to convert a string to hexadecimal format and restore the original string when outputting in reverse. As a popular server-side scripting language, PHP provides rich string processing functions and hexadecimal conversion functions, which can easily complete this task. This article will introduce how to convert a string to hexadecimal and reverse output through PHP, and provide specific code examples. Step 1: Convert string to hexadecimal First, we need to write a P

Translate Pandigital numbers in C++ into Chinese under the given base system Translate Pandigital numbers in C++ into Chinese under the given base system Aug 30, 2023 am 08:01 AM

A number that contains all digits from 0 to base B is called a total number in that base. However, some numbers have digits from 1 to 9 and are called zero-free full digit numbers. Some examples of fully numeric numbers include 0123456789, 0789564312, etc. In this tutorial, we will discuss a problem where we are given a number and a base and we need to check if the number is a fully numeric number in the given base, for example -Input:num="9651723467380AZ",base=10Output: YESExplanation:numcontainsallthedig

Revealing the Programmer's Coding Secret: A Guide to PHP Octalism Revealing the Programmer's Coding Secret: A Guide to PHP Octalism Jan 13, 2024 am 09:27 AM

PHP octal: Decrypting the programmer's coding password Introduction: In the world of programmers, coding is one of the most basic skills. Coding enables computers to understand and execute our instructions to complete various tasks. However, sometimes programmers may need to encrypt data to ensure data security. Base encoding is one of the commonly used encryption methods. This article will introduce some common operations on base encoding in PHP8, as well as specific code examples. 1. What is hexadecimal encoding? Base is a mathematical counting system that

Problems and solutions to Chinese garbled characters in hexadecimal to string conversion encountered in PHP development Problems and solutions to Chinese garbled characters in hexadecimal to string conversion encountered in PHP development Mar 05, 2024 am 08:24 AM

Problems and solutions to Chinese garbled characters in hexadecimal conversion to strings encountered in PHP development In PHP development, sometimes we encounter the need to convert data in hexadecimal form into strings, but in this process it may There will be problems with Chinese garbled characters. This article will introduce specific problem analysis and solutions, and attach code examples, hoping to help developers with similar needs. Problem Analysis In PHP development, when we obtain data in hexadecimal form from the database or other sources, we need to convert it into a string for processing.

See all articles