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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:08:01+00:00 2026-05-23T03:08:01+00:00

So, I’m having a little trouble trying to make a card reader work properly

  • 0

So, I’m having a little trouble trying to make a card reader work properly on a Multi-functional printer and I’ve narrowed down my problem to the weird value a string outputs when a byte[] is passed as a constructor argument. I can’t really debug the application over the MFP and the logging tool simply doesn’t work alongside the card-reading application (that’s the embedded programming world for you, folks!), so my work debugging work is pretty much based on printing values on screen that, sometimes, doesn’t quite behave as you’d like.

Ok, here we go: when I “swipe” the card on the reader, my Java program receives a byte[]. Now, there are two ways I can display it:

    //Supposing that bytes is the byte[] received
    BigInteger bi = new BigInteger(bytes); bi.toString(16); //I think it works fine
    String str = new String(bytes); //Suggested by the developer; sucks

Ok. The first one outputs “3538353536”. Kinda weird for a hex value, but it is actually the right value; since I ran a test:

    byte[] bytes = {0x35, 0x38, 0x35, 0x35, 0x36};
    BigInteger bi = new BigInteger(bytes);
    System.out.println(bi.toString(16));

Considering that it returns the same value (3538353536), I’ll take it as the actual byte[] value. Now, when I try the second way:

    new String(bytes);

In this case, my return value is 58556. Even worse, things are not so happy every time, as passing as an argument something like

    {(byte)9F, (byte)0xA8, (byte)0xEE};

will output [tab – really a tab, not write tab] ¨î

I’ve read in a few places that new String (bytes) was the right way to go, even more so it is the card reader developer’s example. But it doesn’t work. Before I go about questioning the developer, I’d like to know what this output means compared to bi.toString(16), which seems the right way to go.

Sorry about the rather lenghty post about a question that could be summarized in two lines, but I’d like to make everything crystal clear for a straight, quick answer.

EDIT: Thanks for the input everyone, I got it. Now I’m confused whether I should consider the ASCII value (58556) or the hex (“0x3538353536”) – that is, if it is actually supposed to be interpreted as hex – but that’s a question I’ll take to the developer.

  • 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-23T03:08:01+00:00Added an answer on May 23, 2026 at 3:08 am

    As the javadocs say, String(bytes) “constructs a new String by decoding the specified array of bytes using the platform’s default charset”.

    So what’s happening is it’s interpreting the data as being characters stored in byte format. If you look up an ASCII chart you’ll see that 0x35 = ‘5’, etc.

    ToString on the other hand converts the data to a string representation, as you’d expect.

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

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.