dpikoto468637
2014-10-17 06:57 阅读 53
已采纳

如何将用户ID(int)编码/解码为8位数的数字格式

I want to encode user_id(it's always in inter) into numeric format upto maximum 8 to 10 digit number.

Like User_id = 86 it will encode like this way 25413657(any numeric format )

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dongsisui7562 dongsisui7562 2014-10-17 07:16

    You can use decimal to binary if security is not the issue.

    //86 to 8 bit binary
    $bin = decbin(86)
    $bin = substr("00000000",0,8 - strlen($bin)) . $bin;
    
    echo $bin; //01010110
    
    //$bin to dec i.e 86
    echo bindec($bin); //86
    

    OR

    as also can use any of your own formula to convert.

    OR

    you can use PHP hash

    点赞 评论 复制链接分享

相关推荐