Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 969811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:42:13+00:00 2026-05-16T02:42:13+00:00

Is there a common method to encode and decode arbitrary data so the encoded

  • 0

Is there a common method to encode and decode arbitrary data so the encoded end result consists of numbers only – like base64_encode but without the letters?

Fictitious example:

$encoded = numbers_encode("Mary had a little lamb");

echo $encoded; // outputs e.g. 12238433742239423742322 (fictitious result)

$decoded = numbers_decode("12238433742239423742322");

echo $decoded; // outputs "Mary had a little lamb"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:42:14+00:00Added an answer on May 16, 2026 at 2:42 am

    You can think of a (single byte character) string as a base-256 encoded number where “\x00” represents 0, ‘ ‘ (space, i.e., “\x20”) represents 32 and so on until “\xFF”, which represents 255.

    A representation only with numbers 0-9 can be accomplished simply by changing the representation to base 10.

    Note that “base64 encoding” is not actually a base conversion. base64 breaks the input into groups of 3 bytes (24 bits) and does the base conversion on those groups individually. This works well because a number with 24 bits can be represented with four digits in base 64 (2^24 = 64^4).

    This is more or less what el.pescado does – he splits the input data into 8-bit pieces and then converts the number into base 10. However, this technique has one disadvantage relatively to base 64 encoding – it does not align correctly with the byte boundary. To represent a number with 8-bits (0-255 when unsigned) we need three digits in base 10. However, the left-most digit has less information than the others. It can either be 0, 1 or 2 (for unsigned numbers).

    A digit in base 10 stores log(10)/log(2) bits. No matter the chunk size you choose, you’re never going to be able to align the representations with 8-bit bytes (in the sense of “aligning” I’ve described in the paragraph before). Consequently, the most compact representation is a base conversion (which you can see as if it were a “base encoding” with only one big chunk).

    Here is an example with bcmath.

    bcscale(0);
    function base256ToBase10(string $string) {
        //argument is little-endian
        $result = "0";
        for ($i = strlen($string)-1; $i >= 0; $i--) {
            $result = bcadd($result,
                bcmul(ord($string[$i]), bcpow(256, $i)));
        }
        return $result;
    }
    function base10ToBase256(string $number) {
        $result = "";
        $n = $number;
        do {
            $remainder = bcmod($n, 256);
            $n = bcdiv($n, 256);
            $result .= chr($remainder);
        } while ($n > 0);
    
        return $result;
    }
    

    For

    $string = "Mary had a little lamb";
    $base10 = base256ToBase10($string);
    echo $base10,"\n";
    $base256 = base10ToBase256($base10);
    echo $base256;
    

    we get

    36826012939234118013885831603834892771924668323094861
    Mary had a little lamb
    

    Since each digit encodes only log(10)/log(2)=~3.32193 bits expect the number to tend to be 140% longer (not 200% longer, as would be with el.pescado’s answer).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a common method/api to list all web browsers (name, executable, default yes/no)
Evening, Is there a common or standardised name given to a function or method
Some DOM selection methods like getElementsByClassName() are common to HTMLDocument and HTMLElement. Is there
Question: What is the standard method for accessing back end data, which logon should
Is there a common method/best practice/any means for combining forms that span multiple related
There is a common method when using JTable TableCellRenderers for setting the background and
Is there a standard/common method/formula to calculate the number of months between two dates
I have situation where there are multiple test cases which uses a common method.
Is there a common standard for reporting errors in your class functions? I've seen
Is there a common interface in Python that I could derive from to modify

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.