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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:35:31+00:00 2026-06-15T17:35:31+00:00

Hey I cant figure out what is wrong here. Write to file: byte[] dim

  • 0

Hey I cant figure out what is wrong here.

Write to file:

byte[] dim = new byte[2];
dim[0] = (byte) deImgWidth; // Input 384
dim[1] = (byte) deImgHeight; // Input 216
out.write(dim);

Read from File

byte[] file = new byte[(int) f.length()];
FileInputStream fs = new FileInputStream(f);
fs.read(file);
deImgWidth = ((file[0]) & 0xFF); // output 128
deImgHeight = ((file[1]) & 0xFF); // output 216

How come I can retrieve the same deImgHeight value but not the same deImgWidth value?

  • 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-15T17:35:31+00:00Added an answer on June 15, 2026 at 5:35 pm

    384 doesn’t fit into an unsigned byte while 216 does. That’s why when casting the former you must lose information.

    Narrowing conversions just preserve the lowest bits of a number, so if you do the extra & 0xFF when you read your value, you can later restore the sign (since Java uses two’s complement for negative numbers). 216 = 0b11011000 (fits into 8 bits) can be losslessly transformed, but 384 = 0b110000000 (that’s 9 bits) – when you take the lower 8 bits, you end up with 128.

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

Sidebar

Related Questions

Hey everyone - I cant seem to figure out what i am doing wrong
hey guys having this really simple problem but cant seem to figure out have
Hey, I can't figure out what is wrong with this beans definition. I'm getting
Hey I can't figure out what the equation to find the new angle of
Hey, I can't figure out how to write a regular expression for my website,
Hey, trying to figure out a way to use a file I have to
Hey guys, I have this quick bit of code that I can't figure out
Hey guys, I'm reviewing some questions but I can't really figure it out, i
Hey, I'm trying to create Like Buttons for Facebook Photos, but can't figure out
Hey guy's I can't figure out why my code doesn't work when I have

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.