5 changed files with 145 additions and 56 deletions
@ -0,0 +1,40 @@ |
|||||
|
<?php |
||||
|
namespace App\Http\Services; |
||||
|
|
||||
|
|
||||
|
class CommonService{ |
||||
|
/** |
||||
|
* 十进制小数转十六进制 |
||||
|
* @param float $decimal |
||||
|
* @param $len |
||||
|
* @return string |
||||
|
*/ |
||||
|
public static function customDec2hex(float $decimal, $len = 8) { |
||||
|
$hex = ''; |
||||
|
$count = 0; |
||||
|
# 只取小数部分 |
||||
|
$decimal = fmod($decimal, 1); |
||||
|
while ($count++ < $len) { |
||||
|
$dec16 = $decimal * 16; |
||||
|
# 取整 转16进制 |
||||
|
$hex .= dechex((int)$dec16); |
||||
|
# 取小数部分 |
||||
|
$decimal = fmod($dec16, 1); |
||||
|
} |
||||
|
return $hex; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 十六进制小数转十进制 |
||||
|
* @param $hexadecimal |
||||
|
* @return float|int |
||||
|
*/ |
||||
|
public static function customHex2dec($hexadecimal) { |
||||
|
$dec = 0; |
||||
|
for ($i = 0; $i < strlen($hexadecimal); $i++) { |
||||
|
$dec += hexdec($hexadecimal[$i]) / pow(16, $i + 1); |
||||
|
} |
||||
|
|
||||
|
return $dec; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
<?php |
||||
|
|
||||
|
return [ |
||||
|
'lora_mac' => [ |
||||
|
// "616162626364", |
||||
|
// "616162626365", |
||||
|
"616162626366", |
||||
|
], |
||||
|
]; |
||||
|
Before Width: | Height: | Size: 979 B After Width: | Height: | Size: 3.6 KiB |
Loading…
Reference in new issue