# unsigned variable problem

I have an alghoritm written in C. Few functions use unsigned variables, just like unsigned int, unsigned char etc. I just wonder if it's possible for me to translate that code to PHP as all numeric variable types in PHP are signed.
Is there any easy way to solve that or do i have to convert value to unsigned after every operation?
How can i make PHP to use variable as an 'unsigned char' and not 'char'?

Just one example:

unsigned char calculo4_a (char caracter)
{
unsigned char aux1, aux2, aux3, temp;
int i;

aux1=0;
aux2=7;
temp=0;

for (i=0; i<8; i++)
{
aux3=caracter;
aux3=aux3>>aux2;
aux3&=1;
aux3=aux3<<aux1;
temp|=aux3;
aux1++;
aux2--;
}
return temp;
}
LVL 5
###### Who is Participating?

Commented:
If you give the mask as
all the upper bits are erased and made as 0's.

So if want it as 16-bit integer, you also need to pass the mask value to the method
In this case, you have to specify

0

Commented:
It doesn't matter whether it is int or unsigned int.
0

Commented:
In C char size is 8 bits that the maximum number possible is 255.
If you use  a variable in php, it is implicitly understood as int if you assign a int... the maximum is way more that 255.
So you need not worry about it.

function calculo4_a (\$caracter)
{
\$aux1=0;
\$aux2=7;
\$aux3=0;
\$temp=0;

for (\$i=0; \$i<8; \$i++)
{
\$aux3=\$caracter;
\$aux3=\$aux3>>\$aux2;
\$aux3 &=1;
\$aux3 =\$aux3<<\$aux1;
\$temp |=\$aux3;
\$aux1++;
\$aux2--;
}
\$temp;
}

\$x = calculo4_a (10);
0

Commented:
Discard the above post, I was wrong...
0

Commented:
try this code.. it should work...

function calculo4_a (\$caracter)
{
\$aux1=0;
\$aux2=7;
\$aux3=0;
\$temp=0;

for (\$i=0; \$i<8; \$i++)
{
\$aux3=\$caracter;
\$aux3 =(\$aux3 & 1) & \$mask ;
\$temp = (\$temp|\$aux3) & \$mask ;
\$aux1 = (\$aux1 + 1) & \$mask ;
\$aux2 = (\$aux2 -1) & \$mask ;
}
\$temp;
}

\$x = calculo4_a (10);
0

Commented:
Correction,

0

Author Commented:
and how the mask would look for 'integer' and 'shortint'?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.