donglu5728 2014-06-21 09:27
浏览 27

在php中将septet转换为八位字节

I need to convert septets to octest like this c example:

private void septetToOctet()
{
    int len = 1;
    int j = 0;
    int septetcount = septet.Count;

    while (j < septet.Count - 1)
    {
        string tmp = septet[j]; // storing jth value
        string tmp1 = septet[j + 1]; //storing j+1 th value
        string mid = SWAP(tmp1);
        tmp1 = mid;
        tmp1 = tmp1.Substring(0, len);
        string add = SWAP(tmp1);
        tmp = add + tmp;// +"-";
        tmp = tmp.Substring(0, 8);
        //txtoctet.Text += tmp + " || ";
        octet.Add(tmp);
        len++;
        if (len == 8)
        {
            len = 1;
            j = j + 1;
        }
        j = j + 1;
    }
}

..only problem is - i need to do it in php. Does anybody have an code example for this ?

  • 写回答

1条回答 默认 最新

  • doulingzhuang3079 2014-06-21 10:06
    关注

    Most of the code can be translated to PHP with little changes. For instance, the first two assignments would be just $len = 1 and $j = 0. There is no strong static typing in PHP.

    Since numbers and strings are scalars in PHP, you cannot call methods on them, so you cannot do tmp1.substring but would have to do substr($tmp1, …).

    septet and octet would be arrays in PHP. Again, there is no methods on arrays in PHP. To add to an array, you simply do $octet[] = $tmp. To count the elements you do count($septet).

    There is no SWAP in PHP, but you can derive the rather trivial function from Is there a built in swap function in C?

    These hints should get you closer to a working implementation.

    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示