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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:57:36+00:00 2026-06-15T18:57:36+00:00

I m new in java.I have a text document with hexadecimal values line by

  • 0

I m new in java.I have a text document with hexadecimal values line by line, i m trying to read it and convert it into byte array. but for the hexadecimal values like 8, d, 11, 0, e4 when parsing i m getting wrong value for e4 as -28 instead of 228.
how can i overcome this conversion error….

          FileInputStream fstream = new FileInputStream("C:/Users/data.txt");

          DataInputStream in = new DataInputStream(fstream);
          BufferedReader br = new BufferedReader(newInputStreamReader(in,"UTF-8"));


          byte[] bytes = new byte[1024];
          String str;
          int i=0;

          while ((str = br.readLine()) != null) 
          {

              bytes[i]= (byte) (Integer.parseInt(str,16) & 0xFF);
              i++;

          }
          byte[] destination = new byte[i];
          System.arraycopy(bytes, 0, destination, 0, i);

          br.close();
          return destination;
  • 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-15T18:57:37+00:00Added an answer on June 15, 2026 at 6:57 pm

    As Alnitak said byte is signed in java. Value of 0xe4 = 228 which is unsigned, and the range of byte is -128 to 127.

    My suggestion is to use int instead of byte like

    int[] bytes = new int[1024];
    bytes[i]= Integer.parseInt(str,16);
    

    You get the same thing which you have require.

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

Sidebar

Related Questions

I am new to Java. I just read that class variables in Java have
I'm new to Java and have gotten myself into a situation where it's evident
I have a Java program that reads some text from a file, line by
I am new in Java and have got as a task to find out,
Forgive me, I'm new to Java and have an extremely basic question. I have
Like lots of askers on SO, I'm relatively new to java and have attempted
Completely new to java and I have been playing around with regex in a
I am new to java and I have some problem on Casting. I have
I'm new to Java EE and have been struggling with some basic middleware concepts
I'm new to Java and I have a beginner question: NumberFormat is an abstract

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.