添加2个十六进制字符串 [英] Adding 2 hexadecimals as strings

查看:214
本文介绍了添加2个十六进制字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

描述



我试图从steam
http://forums.steampowered.com/forums/showthread.php?t=2695676



使用的数据

蒸汽库存物料属性

属性 :[

defindex:152,
value:160020469,
float_value:3.3154542658454145e-033
},
{
defindex:227,
value:142668139,
float_value:7.7604768692394667e-034
},
{
defindex :746,
value:1065353216,
float_value:1
},
{
defindex:292,
value :1115684864,
float_value:64
},
{
defindex:388,
value:1115684864,
float_价值:64
}
]



我的脚本





 函数Function_BigDecimal_to_Hexadecimal_Converter($ dec){
$ hex ='';
do {
$ last = bcmod($ dec,16);
$ hex = dechex($ last)。$ hex;
$ dec = bcdiv(​​bcsub($ dec,$ last),16);
} while($ dec> 0);
return $ hex;
}
函数Function_BigHexadecimal_to_Decimal_Converter($ hex){
$ dec = 0; $ len = strlen($ hex);
for $($ i = 1; $ i <= $ len; $ i ++){$ dec = bcadd($ dec,bcmul(strval(hexdec($ hex [$ i - 1])),bcpow '16',strval($ len - $ i)))); }
return $ dec;
}

$ hex1 = Function_BigDecimal_to_Hexadecimal_Converter('142668139'); //数据来自defindex 227
$ hex2 = Function_BigDecimal_to_Hexadecimal_Converter('160020469'); //来自defindex的数据152

echo'hex1',$ hex1,'< br>'; // = 880f16b
echo'hex2',$ hex2,'< br>'; // = 989b7f5


$ hex_append = $ hex1。$ hex2;
echo'hex_append',$ hex_append,'< br>'; // = 880f16b989b7f5

$ ugcid = Function_BigHexadecimal_to_Decimal_Converter($ hex_append);
echo'ugcid',$ ugcid,'< br>'; // = 38297187109156853

`



我的问题



期望的ucid值应该是 612754991346202613 并且我得到了 38297187109156853

在这里,我将这段代码倒过来,从预期的答案中获得hex_append

echo'使用期望答案逆转hex_append'.Function_BigDecimal_to_Hexadecimal_Converter('612754991346202613'); // = 880f16b0989b7f5



结论



在计算出的 880f16b989b7f5 和相反的回答 880f16b0989b7f5 之间的差异是 0

我该如何解决这个问题?

我猜想在添加2个hexes作为字符串时有时需要添加0。

仅此项目检测到此问题。



所有这些php代码都会被拷贝到一个php文件中并执行

解决方案

答案:该字符串必须有18个字符


Description

I'm trying to get the data for a decall image for a Team Fortress 2 item from steam http://forums.steampowered.com/forums/showthread.php?t=2695676

Data used

steam inventory item attributes "attributes": [ { "defindex": 152, "value": 160020469, "float_value": 3.3154542658454145e-033 }, { "defindex": 227, "value": 142668139, "float_value": 7.7604768692394667e-034 }, { "defindex": 746, "value": 1065353216, "float_value": 1 }, { "defindex": 292, "value": 1115684864, "float_value": 64 }, { "defindex": 388, "value": 1115684864, "float_value": 64 } ]

My script

`

function Function_BigDecimal_to_Hexadecimal_Converter($dec) {
    $hex = '';
    do {    
        $last = bcmod($dec, 16);
        $hex = dechex($last).$hex;
        $dec = bcdiv(bcsub($dec, $last), 16);
    } while($dec>0);
    return $hex;
}
function Function_BigHexadecimal_to_Decimal_Converter($hex) {
    $dec = 0;  $len = strlen($hex);
    for ($i = 1; $i <= $len; $i++) {  $dec = bcadd($dec, bcmul(strval(hexdec($hex[$i - 1])), bcpow('16', strval($len - $i)))); }
    return $dec;
}

$hex1 = Function_BigDecimal_to_Hexadecimal_Converter('142668139' ); // data from defindex 227
$hex2 = Function_BigDecimal_to_Hexadecimal_Converter('160020469'); // data from defindex 152

echo 'hex1 ',$hex1,'<br>'; // = 880f16b
echo 'hex2 ',$hex2,'<br>'; // = 989b7f5


$hex_append =  $hex1.$hex2;
echo 'hex_append ',$hex_append,'<br>'; // = 880f16b989b7f5

$ugcid = Function_BigHexadecimal_to_Decimal_Converter($hex_append);
echo 'ugcid ',$ugcid,'<br>'; // = 38297187109156853

`

My problem

expected ucid value shoud be 612754991346202613 and I got 38297187109156853

Here i'm reversing this code to get hex_append from the expected answer

echo 'Reversed hex_append using expected answer '.Function_BigDecimal_to_Hexadecimal_Converter('612754991346202613');// = 880f16b0989b7f5

Conclusion

The difference in hex_append calculated 880f16b989b7f5 and the reversed answer 880f16b0989b7f5 is a 0
How can I fix this ?
I guess the a 0 needs to be added sometimes when adding 2 hexes as strings.
This problem was detected only for this item.

All this php code con be copyed in a php file and executed

解决方案

Answer: The string must have 18 characters

这篇关于添加2个十六进制字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆