Write a program to flip an i th bit of a 64-bit integer.

Logic:
A 64-bit integer can be viewed as an array of 64 bits,  with the bit at index 0 corresponding to the least significant bit and the bit at index 63 corresponding to the most significant bit. For above problem, we have flip ith bit, i.e if ith bit is 0 then we have to change it to 1, and vice versa. For this, take a long integer 1, move it to ith position by left sifting, then xor with number.

Program:

<?php 

$a = 134 ;  // original number 
$i = 3  ; //four bit index from  zero 
$b = $a ^ (1 << $i );

printf("Original number : %b" , $a) ;
printf("
After of %d bit  number : %b" , $i, $b) ;

Output:

Original number : 10000110
After of 3 bit number : 10001110
Author: Hrishikesh Mishra