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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:06:48+00:00 2026-05-27T06:06:48+00:00

Possible Duplicate: Literal Syntax For byte[] arrays using Hex notation..? I am trying to

  • 0

Possible Duplicate:
Literal Syntax For byte[] arrays using Hex notation..?

I am trying to create a byte array of size ‘1’ that holds the byte 0x0. In Java, can I just do something like this:

byte[] space = new byte[1];
space[0] = 0x0;

Will the hex value 0x0 be converted to its byte rep of 00000000 and store it in space[0]?

  • 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-27T06:06:49+00:00Added an answer on May 27, 2026 at 6:06 am

    Will the hex value 0x0 be converted to its byte rep of 00000000 and store it in space[0]?

    In your executing program, there is only one representation of the Java byte value zero – the 8 bit 2’s complement representation of the integer zero – 8 zero bits.

    It doesn’t make any difference whether you express the number literal in your source code as 0 (decimal) or 00 (octal) or 0x0. They all mean exactly the same thing.


    So – Yes, your code does what you expect.

    A simpler one line version would be:

    byte[] space = new byte[] {0};
    

    or

    byte[] space = {0};
    

    or even

    byte[] space = new byte[1];
    

    (The last one relies on the fact that Java byte arrays are default initialized to all zeros.)


    Will the hex value 0x0 be converted to its byte rep of 00000000 and store it in space[0]?

    Sort of yes. Technically (i.e. according to the JLS) what happens is this:

    1. 0x0 becomes an int literal. (The specific syntax used for the integer literal is actually immaterial at this point … so long as it is valid.)
    2. The int literal is narrowed using an implicit primitive narrowing conversion to a byte value.
    3. The byte value is used in the initialization of the array.

    The implicit narrowing in step 2 is allowed because:

    1. This is in an assignment context.
    2. The value being assigned is a compile time constant expression of an integer type. (A literal is a compile time constant expression.)
    3. The actual value being assigned is in the range of the type it is to be assigned to. (In this case, -128 to +127.)

    In layman’s terms, the compiler "knows" that there will never be any loss of information in the narrowing conversion.

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

Sidebar

Related Questions

Possible Duplicate: array_splice() for associative arrays How to add an array value to the
Possible Duplicate: XPath: How to match attributes that contain a certain string I'm trying
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: Self-references in object literal declarations How do I do the following: var
Possible Duplicate: How do I write a short literal in C++? I can use
Possible Duplicate: How do you express binary literals in Python? When using the interactive
Possible Duplicate: PHP get all arguments as array? Within a javascript function arguments always
Possible Duplicate: Can you define “literal” tables in SQL? Occasionally I find myself in
Possible Duplicate: Self-references in object literal declarations I have an object literal which is
Possible Duplicate: difference between string object and string literal When initializing a String object

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.