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 8692749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:22:51+00:00 2026-06-13T00:22:51+00:00

Possible Duplicate: Compress 21 Alphanumeric Characters in to 16 Bytes I have 8 numbers

  • 0

Possible Duplicate:
Compress 21 Alphanumeric Characters in to 16 Bytes

I have 8 numbers

is there a way to convert it to a string which length is 4?

for instance:

input 12345678

output AB2D

the conversion should be able to convert back exactly.

I tried to convert it to 32 Hex, but it still has 5 numbers, and I can’t use 0 1 O I in the final string. Is there any good suggestions? btw, only upper case letters could be used.

  • 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-13T00:22:53+00:00Added an answer on June 13, 2026 at 12:22 am

    It comes down to maths. If you need to be able to represent 10^8 possible numbers and you need to use 4 symbols, each symbol must allow 100 different values. 10^8^(1/4) You can do this using an 8-bit byte but your requirement of only upper case letters could be used. suggests your options are rather limited. You have to determine 100 letters you can use or you have to make assumptions about the range of numbers you can have.

    BTW: If you can use non-ASCII upper case characters you don’t have a problem. 😉

    There are 26 upper case ASCII characters, 30 upper case characters between 128 and 255 and 10 digits so you would have to use 34 symbols as well. If you can use Unicode, there are 1898 upper-case and digit Unicode characters.

    There is 163 non lower-case characters between (char) 32 and (char) 255 and if you can use most of these you can do it.


    A hand picked list of possible characters will be a better choice but this is an example.

    static final char[] ENCODE = new char[100];
    
    static {
        int x = 0;
        for (char i = ' ' + 1; i < 256 && x < 100; i++)
            if (!Character.isLowerCase(i) && !Character.isWhitespace(i))
                ENCODE[x++] = i;
        assert x == ENCODE.length;
    }
    
    public static char[] encode(int n) {
        assert n >= 0 && n < 100000000;
        char[] ret = new char[4];
        for (int i = ret.length - 1; i >= 0; i--) {
            ret[i] = ENCODE[n % 100];
            n /= 100;
        }
        return ret;
    }
    
    public static int decode(char[] chars) {
        int n = 0;
        for (char ch : chars) {
            int x = Arrays.binarySearch(ENCODE, ch);
            assert x >= 0;
            n = n * 100 + x;
        }
        return n;
    }
    
    public static void main(String... args) {
        char[] chars = encode(12345678);
        System.out.println("Encoded: " + new String(chars));
        int n = decode(chars);
        System.out.println("Dencoded: " + n);
    }
    

    prints using a character which is non-printable in this font 🙁

    Encoded: -CY
    Dencoded: 12345678
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Objective C for Windows iPhone development on Windows Is there any way
Possible Duplicate: HTML Compress File Upload? I have complains from client that my website
Possible Duplicate: C++ convert int and string to char* Hello, i am making a
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: Python urllib2 Progress Hook I have a script which uploads a file
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: How can I obfuscate JavaScript? Hi, I want to compress a JavaScript
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: Can a Bash script tell what directory it's stored in? Is there
Possible Duplicate: std::string and its automatic memory resizing I am just curious, how are

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.