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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:22:10+00:00 2026-06-15T05:22:10+00:00

I need to represent a value of 0xFF00 as two bytes (in Java). I

  • 0

I need to represent a value of 0xFF00 as two bytes (in Java). I am trying to do it like this:

int val = 0xFF00;
bytearray[0] = (byte)((val >> 8) & 0xFF);
bytearray[1] = (byte)((val >> 0) & 0xFF);

I know that byte in Java can hold values 0-255. So I expect the first array element to have a value of 255 and the second element to be zero. But what I am getting instead is -1 and 0. What I am doing wrong? What this -1 value mean?

  • 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-15T05:22:11+00:00Added an answer on June 15, 2026 at 5:22 am

    Byte in java is from -128 to 127, not from 0 to 255

    -1 is 1111 1111 in two’s complement binary, equal to 255 in unsigned byte.

    You aren’t doing anything wrong, you just need to know that if you see -1, it means the byte is representing the bits 1111 1111.

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

Sidebar

Related Questions

I have a uint value that I need to represent as a ByteArray and
How can i represent a 3D coordinate as a singular value? I need this
I need to represent the time in (%m/%d/%Y %H:%M:%S) format from the float value
We need to represent huge numbers in our application. We're doing this using integer
I need to represent huge data(37 columns,1000+ rows) in web. I would like to
I need to represent a condition where the value of the JSpinner is not
I have a floating point value, but when i need to represent to the
I have 6000 data of district, subdistrict. I need to represent this on dependent
I need a class that can represent probabilities. It can be represented like a
I need to store set value in MySQL column. I completely like the build-in

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.