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

  • Home
  • SEARCH
  • 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 9135355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:48:48+00:00 2026-06-17T08:48:48+00:00

I need to convert the following to a binary format (and later recoup) in

  • 0

I need to convert the following to a binary format (and later recoup) in the smallest amount of data possible.

my_arr = [
        [128,32 ,22,23],
        [104,53 ,21,25],
        [150,55 ,79,23],
        [104,101,23,8 ],
        [57 ,117,13,21],
        [37 ,135,21,20],
        [81 ,132,23,6 ],
        [81 ,138,7 ,8 ],
        [97 ,138,7 ,8 ]...

the numbers don’t exceed 399

If I use a 0 for each digit (8 0’s in a row = 8) and a 1 as separator, the first line looks like this:
010010000000011000100110010011001000
This is really long for numbers like 99

If I pad each number to three digits and convert each in turn to actual binary the first line looks like this:
000100101000000000110010000000100010000000100011
This works out as 12 chars per number.

As the first char won’t ever be a 4 or above I can save two digts by treating 0 as 00, 1 as 01, 2 as 10 and 3 as 11. Hence 10 chars per number
On the whole this reduces the size down to about 90% of the first option (on average) but is there a shorter way?

edit: yes as a string of 1’s and 0’s… and it doesn’t need to be shorter than the original integers… just the shortest possible way of writing it using only 2 symbols

  • 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-06-17T08:48:49+00:00Added an answer on June 17, 2026 at 8:48 am

    A good starting point would be to create constant-length blocks of ones and zeroes, which gives you easy to decode strings.

    400 in binary is 110010000, which requires 9 characters to encode each number as its binary representation zero-padded to constant length.

    encoding the first row:

    var padTo9 = function( bin ){ 
        while( bin.length<9 ){ bin = "0" + bin; } 
        return bin; 
    }
    [128,32 ,22,23].map( function(i){ return padTo9( i.toString(2) ) }).join('');
    
    /* result:
    "010000000000100000000010110000010111"
    */
    

    decoding

    "010000000000100000000010110000010111".match(/[0-1]{9}/g).map( function(i){ return parseInt( i, 2 ) });
    /* result:
    [128, 32, 22, 23]
    */
    

    I think the only way to get shorter string is using variable block length, which would require adding some control symbols to tell the decoder that following numbers are encoded in a specific number of characters. But these symbols have to be in >400 and still 9 characters long, so I think it wouldn’t help given random distribution of data.

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

Sidebar

Related Questions

I need to convert a Joda-Time DateTime into a String, in the following format:
I need to convert a huge file into the following format: for each byte,
I need to convert the following format into a new format using NSDateFormatter. 'Fri,
I need to convert the following string into a better readable format: NSString *deadlineFromTable
I need to convert the following java method to scala and am having difficulty
I need to convert all of the following forms into .NET Uri object: hello.world
I have the following int 7122960 I need to convert it to 71229.60 Any
I have the following FORTRAN code which I need to convert to C or
I need to convert a column data into single row with multiple columns Example
I need to convert a binary file (a zip file) into hexadecimal representation, to

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.