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

Ask A Question

Stats

  • Questions 499k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is not pretty but it works: rm -R $(ls… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer Yes. Override the base1 and base2 methods in Derived to… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer No, you can't. Unfortunately, UIEvent doesn't expose any public way… May 16, 2026 at 12:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a very common situation and a solution, but I would like to
It seems like the elevation of privileges is a common thing most developers fight
My GWT module UI is only single button ( like AddThis/ShareThis Sharing Button ),
In my application I have lots of different data types, e.g. Car, Bicycle, Person,
I have a common class say for eg Class A which extends AsyncTask and
I've got a handler (list.ashx for example) that has a method that retrieves a
This is the first time I am working for a front-end project that requires
I think its fairly common practice these days not to include a mailto: tag
I want to do what's described in question 724043 , namely encode the path
As part of one of my projects, there are BeforeBuild tasks that ultimately generate

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.