Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
I would like to change a string of numbers of length 54 characters from base 10 to base 16 in js or php
<?php
    function base16($str){
        $str = base_convert($str,10,16);
        echo $str;
    }
    base16("000012345678920190113163721231000011101000000000100001");

    //8727f63a15f8a0000000000000000000000000000
?>

I have this number array in base 10

000012345678920190113163721231000011101000000000100001

and the expected result should be

8727F63A15F8976591FDDE5B387C5D015A29E06A1
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can use BigInt to solve this in JS

console.log(
  BigInt(
      "000012345678920190113163721231000011101000000000100001"
  ).toString(16)
)

about 4 years ago · Juan Pablo Isaza Report

0

You can try this-

function convBase($numberInput, $fromBaseInput, $toBaseInput)
{
    if ($fromBaseInput==$toBaseInput) return $numberInput;
    $fromBase = str_split($fromBaseInput,1);
    $toBase = str_split($toBaseInput,1);
    $number = str_split($numberInput,1);
    $fromLen=strlen($fromBaseInput);
    $toLen=strlen($toBaseInput);
    $numberLen=strlen($numberInput);
    $retval='';
    if ($toBaseInput == '0123456789')
    {
        $retval=0;
        for ($i = 1;$i <= $numberLen; $i++)
            $retval = bcadd($retval, bcmul(array_search($number[$i-1], $fromBase),bcpow($fromLen,$numberLen-$i)));
        return $retval;
    }
    if ($fromBaseInput != '0123456789')
        $base10=convBase($numberInput, $fromBaseInput, '0123456789');
    else
        $base10 = $numberInput;
    if ($base10<strlen($toBaseInput))
        return $toBase[$base10];
    while($base10 != '0')
    {
        $retval = $toBase[bcmod($base10,$toLen)].$retval;
        $base10 = bcdiv($base10,$toLen,0);
    }
    return $retval;
}
?>

Then

<?php
convBase('000012345678920190113163721231000011101000000000100001', '0123456789', '0123456789ABCDEF');
?>

parameters->

dataToConvert
fromBase
toBase
about 4 years ago · Juan Pablo Isaza Report

0

Can you use GMP ?

<?php
$str = '000012345678920190113163721231000011101000000000100001';
echo strtoupper(gmp_strval(gmp_init($str, 10), 16));
// 8727F63A15F8976591FDDE5B387C5D015A29E06A1
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!