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

  • Home
  • SEARCH
  • 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 426953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:31:50+00:00 2026-05-12T19:31:50+00:00

The Java data type byte for example holds data from -128 to 127 in

  • 0

The Java data type byte for example holds data from -128 to 127 in a single byte on storage.
To enable to distingush between – 1 to -128 from 0 to 127 would require extra data which would take the datatype obver its allocated storage. Admittedly it would only take 1 extra bit but it still goes over.

How does java do this?

  • 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-12T19:31:51+00:00Added an answer on May 12, 2026 at 7:31 pm

    Two’s complement:

    The primitive types are defined to be the same on all machines and in all implementations, and are various sizes of two’s-complement integers, single- and double-precision IEEE 754 standard floating-point numbers, a boolean type, and a Unicode character char type. —The Java Language Specification: Introduction

    You can imagine it as an integer from 0 to 255 from which 128 is always subtracted.

    More technical: an integer can (and will) be negated (positive → negative or vice versa) by inverting its bits and adding one. This is almost like One’s complement (which simply inverts all bits—hence complement. But one’s complement has the problem that it has two different zeroes: +0 and −0 (floating-point numbers have that too, but for other reasons and more useful ☺). Two’s complement solves this by adding one, and thereby extending the range of negative values (that’s why it’s −128..127).

    In some way you could say that the sign is indeed “stored” in the first bit of the number. So your observation that it needs one bit of storage is correct. But the numeric range of a byte (positive or negative, ignoring the sign) only needs 7 bits, so you have a byte again.

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

Sidebar

Related Questions

Which data type in Java can hold just the date and doesn't require a
In java, I know the data type of the result of an arithmetic calculation
I am creating a partially ordered set as an abstract data type in java,
What type of data I should define on my java model for PostgreSQL money
This is strange to me: when I run in Java byte[] data = new
I take data from Java to Flex by AMF (BlazeDS) In java side object
I'm looking for a Java built-in data structure that would be the best at
Coming from a Java background, I'm quite fond of static type safety and wonder
What is the easiest way to convert byte array into Blob data type in
I have the following Java code: public static BufferedImage createImage(byte[] data, int width, int

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.