Hello,
I'm sure theres a way to make this simpler but I haven't been able to
figure it out.....heres whats going on:
$tnum = array();
for($i = 0; $i < count($targets['id']); $i++)
{
$tnum[] = hexdec($targets['flags'][$i]);
$headr = substr(sprintf( '%032b', $tnum[$i]), 0, -12);
$footr = substr(sprintf( '%012b', $tnum[$i]), -12);
$fparts = str_split($binC ode, 3);
$hparts = str_split($head r, 4);
echo "{$hparts[0]}-{$hparts[1]}-{$hparts[2]}-{$hparts[3]}-
{$hparts[4]}-";
echo "{$fparts[0]}-{$fparts[1]}-{$fparts[2]}-{$fparts[3]}<br />";
}
Basically, I'm taking these records out of sql, decoding one of the
columns that has hex values, into binary pieces that match a
particular flag. Right now as an example, for "fparts" I'm just using
4 seperate Switch statements for example....here is one of four:
switch ($fparts[0])
{
case '001':
echo "value1 <br />";
break;
case '010':
echo "value2 <br />";
break;
case '011':
echo "value3 <br />";
break;
case '100':
echo "value4 <br />";
break;
case '101':
echo "value5 <br />";
break;
case '110':
echo "value6 <br />";
break;
default:
echo "NO DATA <br />";
}
So each value1-6 is something I need returned and placed into a new
sql column etc.. The echo's above can be replaced with a sql query
and so on, my problem is that I'm sure theres an easier way to do this
without using a hundred plus lines of code for 9 different switch
statements. For instance maybe using logic operators to match the
flags(?) Any help would be much appreciated, thanks!
I'm sure theres a way to make this simpler but I haven't been able to
figure it out.....heres whats going on:
$tnum = array();
for($i = 0; $i < count($targets['id']); $i++)
{
$tnum[] = hexdec($targets['flags'][$i]);
$headr = substr(sprintf( '%032b', $tnum[$i]), 0, -12);
$footr = substr(sprintf( '%012b', $tnum[$i]), -12);
$fparts = str_split($binC ode, 3);
$hparts = str_split($head r, 4);
echo "{$hparts[0]}-{$hparts[1]}-{$hparts[2]}-{$hparts[3]}-
{$hparts[4]}-";
echo "{$fparts[0]}-{$fparts[1]}-{$fparts[2]}-{$fparts[3]}<br />";
}
Basically, I'm taking these records out of sql, decoding one of the
columns that has hex values, into binary pieces that match a
particular flag. Right now as an example, for "fparts" I'm just using
4 seperate Switch statements for example....here is one of four:
switch ($fparts[0])
{
case '001':
echo "value1 <br />";
break;
case '010':
echo "value2 <br />";
break;
case '011':
echo "value3 <br />";
break;
case '100':
echo "value4 <br />";
break;
case '101':
echo "value5 <br />";
break;
case '110':
echo "value6 <br />";
break;
default:
echo "NO DATA <br />";
}
So each value1-6 is something I need returned and placed into a new
sql column etc.. The echo's above can be replaced with a sql query
and so on, my problem is that I'm sure theres an easier way to do this
without using a hundred plus lines of code for 9 different switch
statements. For instance maybe using logic operators to match the
flags(?) Any help would be much appreciated, thanks!
Comment