Q:

Error: Executing visual basics code using php

We are trying to convert a VB system into a web based system using PHP. Currently we are unable to understand few lines in VB which make us hard to convert it to php. 
This is my VB code:
Dim data1 As Byte
Dim data1 As Byte
Dim num = 5117    
data1 = (num >> 6) And &HFF
data2 = num And &H3F

This is my php code:
$data1 = ($num >> 6) && &HFF;
$data2 = $num && &H3F;

Now the problem is, when we run the VB code and output it shows is different than in php. For instance in vb the data2 shows as 61 but in php it shows as 1. Can anyone help us to solve this problem.  

A:

I believe in PHP that the bitwise AND operator is & and not &&.  And hex literals are not specified like that.  Try something like this:
$data1 = ($num >> 6) & 0xFF;
$data2 = $num & 0x3F;

Check the PHP documentation for the bitwise operators. And for hex literals.

