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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:53:47+00:00 2026-05-27T03:53:47+00:00

I have numbers written as ASCII codes in my file. For example 9 is

  • 0

I have numbers written as ASCII codes in my file. For example “9” is stored as two bytes 57 i.e. 8 bits in total.

I want to optimize storage by just storing those numbers as binary values for example numbers from 0-9 to be stored using 4 bits only.

Any help?!

  • 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-27T03:53:47+00:00Added an answer on May 27, 2026 at 3:53 am

    You could write them binary like that

    import java.io.ByteArrayInputStream;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    
    public class Bin {
        public static void main(String[] args) throws IOException {
            FileOutputStream fos = new  FileOutputStream("\\test.bin");
            String digits="12345";
            char[] chars = digits.toCharArray();
            for ( int i = 0 ; i < chars.length ; i+= 2 ) {
                byte b1 = (byte) (chars[i] - (byte) '0');
                byte b2 = (byte) (i < chars.length-1 ? chars[i+1] - (byte) '0' : 0xf);
                fos.write((byte) ((b1 << 4) | b2 ));
            }
            fos.close();
            FileInputStream fis = new FileInputStream("\\test.bin");
            StringBuffer result = new StringBuffer();
            byte[] buf = new byte[100];
            int read = fis.read(buf);
            ByteArrayInputStream bais = new ByteArrayInputStream(buf);
            for ( int i = 0 ; i < read ; i++ ) {
                byte both = (byte) bais.read();
                byte b1 = (byte) ((both >> 4 ) & 0xf);
                byte b2 = (byte) (both  & 0xf) ;
                result.append( Character.forDigit(b1, 10));
                if ( b2 != 0xf ) {
                    result.append(Character.forDigit(b2,10));
                }
            }
            System.out.println(result.toString());
        }
    }
    

    But I doubt that this will be very useful

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

Sidebar

Related Questions

I have numbers written as ASCII codes each of 2 bytes which wastes a
I have written a program in Javascript which reads numbers from a file ,sorts
I have written this code to make a binary file of float numbers, but
I have a number of manually written scripts (.sql) for tables, views and stored
I have numbers in javascript from 01(int) to 09(int) and I want add 1(int)
I have written following regular expression /^[A-Za-z0-9-_\s]*$/ in PHP which allows numbers, letters, spaces,
I have written a PHP application that broadcasts a voice message to phone numbers
I have a database with a column containing a variety of numbers written in
I have a file numbers.dat containing about 300 numbers(floating point,negative positive)in column format. The
I have written a Stored Procedure as shown , which will be responsible 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.