Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Bitwise complement (~)

Complement each bit of a single operand.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

~$value

Complement each bit of a single operand. For an integer this operates over the native integer width, so the complement of zero is negative one. For a string, each byte is independently complemented and the result is another string. Display arbitrary complemented bytes as hexadecimal rather than assuming they form valid text.

~$value
[-1,-6,"be"]

Examples

<?php
echo json_encode([~0, ~5, bin2hex(~"A")]);

Result

[-1,-6,"be"]

Sources