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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:03:26+00:00 2026-06-14T14:03:26+00:00

I have some test code which is not working as I expect, after reviewing

  • 0

I have some test code which is not working as I expect, after reviewing various sites and specifications I still cannot figure out what is happening.

Here is my test code:

byte[] b = new byte[8];
b[0] = (byte)0x72;
b[1] = (byte)0x3A;
b[2] = (byte)0x60;
b[3] = (byte)0x01;
b[4] = (byte)0x0E;
b[5] = (byte)0x10;
b[6] = (byte)0x8A;
b[7] = (byte)0x11;
String bitmapStr = new String(b);
try {
    b = bitmapStr.getBytes("US-ASCII");
} catch (Exception ex) {
    ex.printStackTrace();
}
System.out.println("DEBUG: bitmapStr = \"" +bitmapStr + "\"");
for (int i=0; i<=7; i++) {
    int byte1 = b[i];
    System.out.println("byte"+i + ": " + Integer.toHexString(byte1));
}

When I run the program I get the following in the console output:

DEBUG: bitmapStr = "r:`�"
byte0: 72
byte1: 3a
byte2: 60
byte3: 1
byte4: e
byte5: 10
byte6: 3f
byte7: 11

See how byte6 i.e. b[6] from my byte array outputs 0x3F, but it should be 0x8A.

Any ideas why?

By the way, if I use UTF-8 encoding I get an even more funky output (although ASCII is correct).

UTF-8 String encoding output:

byte0: 72
byte1: 3a
byte2: 60
byte3: 1
byte4: e
byte5: 10
byte6: ffffffef
byte7: ffffffbf
  • 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-14T14:03:26+00:00Added an answer on June 14, 2026 at 2:03 pm

    Following the suggestions from Rahul and irreputabe I figured it out:

    When I changed to UTF-16LE / ISO-8859-1 encoding, byte6 was output as: “ffffff8a”, then I realised I was performing a type conversion from byte to int here:

    int byte1 = b[i];
    

    So I just added:

    int byte1 = b[i] & 0xFF;
    

    for the correct result.

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

Sidebar

Related Questions

I'm working with some legacy test code which makes use of a TestSetup class
I have some code which is working in iphone and i want to make
I'm trying to have some Ajax form in the page which is not working
I have some code that attempts to test whether my application is running with
I have some code in my error handler I need to test against a
I have some basic PHP code: $raceramps56[short] = My Test Product; $leftMenu = '<div
I have some HTML Code: <html> <head> <title>css test</title> <style type=text/css> .box{width:100%;float:left;background:red} </style> </head>
This is a minimal test case of some code that I actually have. It
Suppose I have the following html: This a test of <code>some code</code>. <div class='highlight'>
I have some test cases. The test cases rely on data which takes time

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.