note 128277 added to language.operators.bitwise

From: Date: Fri, 03 Mar 2023 09:56:47 +0000
Subject: note 128277 added to language.operators.bitwise
Groups: php.notes 
Request: Send a blank email to php-notes+get-220234@lists.php.net to get a copy of this message
if you want to set a bit in php you don't need a new extension (avoid using of extensions could be slow down your php!) then with minimum effort you can have: <?php function setbit($v,$b=0){ return (1<<$b)|$v;//($v&$x); } echo sprintf('%b', setbit(0b00000010,0)); /* bits position: 76543210 target number: 0b00000010 bit 0-------------------------^ so bits position: 76543210 result: 00000011 (sprintf will show "11" value) */ ?> same results with anonymous functions from a constant! .. <?php define('setbits',fn($v,$b=0)=>(1<<$b)|$v); echo sprintf('%b',(setbits)(0b00000010,0)); ?> all test i made are on last PHP Version => 8.2.4RC1 ! ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.130 (proxied: 86.124.124.97) ---- Manual Page -- https://php.net/manual/en/language.operators.bitwise.php Edit -- https://main.php.net/note/edit/128277 Del: integrated -- https://main.php.net/note/delete/128277/integrated Del: useless -- https://main.php.net/note/delete/128277/useless Del: bad code -- https://main.php.net/note/delete/128277/bad+code Del: spam -- https://main.php.net/note/delete/128277/spam Del: non-english -- https://main.php.net/note/delete/128277/non-english Del: in docs -- https://main.php.net/note/delete/128277/in+docs Del: other reasons-- https://main.php.net/note/delete/128277 Reject -- https://main.php.net/note/reject/128277 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220234) next »