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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:41:46+00:00 2026-06-13T11:41:46+00:00

So I am sending some stuff over bluetooth, for this I am using byte

  • 0

So I am sending some stuff over bluetooth, for this I am using byte arrays, one of the byte arrays I am using I need to change one of the values before I send it, using this…

private void sendIntensity(int I){
    intensity[3] = (byte) i;
    sendIntensity();
}

The original byte array is made up like this:

private byte[] intensity = new byte[]{58,0,42,0,10,13}

I am getting the intensity from an edit text, getting the text and using regex to find the intensity they want to use, I use

int option = Integer.parseInt(text);

To do that. Basically, any number under 128 works perfectly, I can see this because I log the values in the array, setting it to 127 will log 58, 0, 42, 127, 10, 13 but when I do 128 or over I get a weird set of data when I log it.

The max number I will be putting in there is 255.

When I log what is in the array when use intensity[3] = (byte) 128; I get back 50, 0, 42, -17, -66, -128, 10, 13

When I log what happens when I use 129 I get back 50, 0, 42, -17, -66, -127, 10, 13

What is happening? Why am I not just getting back 50, 0, 42, 128, 10, 13 like I should be?

  • 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-13T11:41:48+00:00Added an answer on June 13, 2026 at 11:41 am

    That’s because byte range is [-128, 127], if you try to set a value larger than 127 in a byte, it will do a round trip to -128, -127 and so on.

    From the SCJP 6 book:

    byte a = (byte) 128;
    

    (…) what’s the result? When you narrow a primitive, Java simply truncates
    the higher-order bits that won’t fit. In other words, it loses all the bits to the left of
    the bits you’re narrowing to.

    More info:

    • Java Primitive Data Types
    • Java in a Nutshell: Primitive Data Types, check the Type Conversions section, the narrowing conversion part.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I send multiple values to be picked up like this using JSON?
I'm writing some pexpect stuff that's basically sending commands over telnet. But, it's possible
I'm sending some data to an external URL using Curl. The server sends me
I'm sending some HTML code back to an iframe using a java servlet and
okay....i'm sending some variables over forms...i tried with borh session and cookie, i'm getting
I have some problems sending mails through SMTP using Spring's MailSender interface and the
Is there some way when sending this message to specify that I rather have
we are sending some data over a serial line, and i can do pretty
The structure looks like this: <form> ... some stuff ... file select ... some
We are looking at sending some email notifications to about 1100 employees at a

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.