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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:57:33+00:00 2026-05-23T08:57:33+00:00

I write the bitstream for a JPEG Encoder, I’m facing this problem: I built

  • 0

I write the bitstream for a JPEG Encoder, I’m facing this problem:

I built Pairs for the AC Cosinus Coefficients (after Quantization) in an int[]array. Each Pair: (Number of Zeros/ Category of the Coefficient after JPEG standard). Out of these two integers, I have to form one hexadecimal number, where as one integer of the pair representing one nibble. The hexadecimal Numbers have to be huffman-encoded later.
Example: My Pair is (4,5), i need it as (0x45).

How can I do that? My way is to convert the Integers to a String, append the Strings, and get them back as one Integer. However, the compiler says

Exception in thread “main” java.lang.NumberFormatException: For input string: “0fffffff5”

//Get a Pair (Numbers of Zeros, Coefficient)
            int[]singlePair_ref = acPairs_ref.get(i);

            //Convert to Wrapper Class Integer
            Integer firstNibble_ref = ((Integer)singlePair_ref[0]);
            Integer secondNibble_ref = ((Integer)singlePair_ref[1]);

            //Convert to String
            String firstNibbleString_ref = firstNibble_ref.toHexString(singlePair_ref[0]);
            String secondNibbleString_ref = secondNibble_ref.toHexString(singlePair_ref[1]);

            //Append Strings
            String byteValueString_ref = firstNibbleString_ref+secondNibbleString_ref;
            Integer byteValue_ref = 0;

            //Convert the new formed "one" (formed out of two) Number back to Integer
            byteValue_ref.parseInt(byteValueString_ref); //Line throws Exception

Hope you can help me. Thanks a lot!
Daniel

Edit:
if I do it like this

YACforHuffman_ref[i] = (singlePair_ref[0] << 4) | singlePair_ref[1];

the out put is decimal (3,6) becomes 54. If I convert the result of this equation with

String YACforHuffman_ref = Integer. Integer.toHexString((singlePair_ref[0] << 4) |    singlePair_ref[1];

like Mike did above, I get trouble for a value bigger than 9 (Value A-F), now I know what you meant @Mike, sorry I didnt get it at first. How can I solve this?

  • 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-23T08:57:33+00:00Added an answer on May 23, 2026 at 8:57 am

    I’m unsure how you would pass in values over 9 into your integer pair but assuming you can pass in 0-15 then you could potentially do something such as this:

    public class Hex {
        public static void main(String[] args) {
            int firstNum  = 4;
            int secondNum = 15;
    
            System.out.println( Integer.toHexString( firstNum * 16 + secondNum ) );
            // Or if you find it easier to understand
            // System.out.println( Integer.toHexString( ( firstNum << 4 ) + secondNum ) );
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Write a class ListNode which has the following properties: int value; ListNode *next; Provide
I write a sh script (test.sh) like this: #!/bin/sh echo $@ and then run
Write a function which has: input: array of pairs (unique id and weight) length
Write a package called Company. Under this package create one other package called salary.
Write a program that calculates Euler’s number e. To do this, first write a
Write a function called swap which has a prototype of void swap (int&, int&);
I'm looking at the C# library called BitStream , which allows you to write
I write to socket with: OutputStream socketStream = socket.getOutputStream(); socketStream.write(buf); But this can throw
Write code to determine if a number is divisible by 3. The input to
Write a program to determine whether a computer is big-endian or little-endian. bool endianness()

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.