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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:27:37+00:00 2026-05-31T05:27:37+00:00

I have a byte array i.e from byte[0] to byte[2] . I want to

  • 0

I have a byte array i.e from byte[0] to byte[2]. I want to first split byte[0] into 8 bits. Then bytes[1] and finally bytes[2]. By splitting I mean that if byte[0]=12345678 then i want to split as variable A=8,Variable B=7, variable C=6,Variable D=5,…….. Variable H=0. How to split the byte and store the bits into variables? I want to do this in JAVA

  • 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-31T05:27:38+00:00Added an answer on May 31, 2026 at 5:27 am

    well the bitwise operations seem to be almost what you’re talking about.
    a byte is composed of 8 bits, and so it goes in the rage of 0 to 255.
    written in binary that’s 00000000 to 11111111.

    Bitwise operations are those that basically use masks to get out as much info as possible out of a byte.

    Say for instance you have your 1101 0011 byte (space added for visibility only) = 211 (decimal). You can split that into 2 “variables” b1 and b2 of half a byte each. they’ll thus cover the range of 0 to 15.

    How you do this is by defining some masks. A mask to get your first half-a-byte-value would be 0000 1111.
    You take your value of 11010011 apply the bitwise and (& ) operator to it.
    So saying byte b = 211; byte mask1=15; OR byte b=0x11010011; byte mask1=0x00001111;
    you then have your variable byte b1=b & mask1;

    Thus applying that operation would result in b1=00000011 = 3;
    With a mask byte mask2=0x11110000; applying the same operation on b, you’d get byte b2=mask2 & b = 0x11010000;

    Now of course that leaves the number b2 possibly too large for you. All you have to do if you want to grab the value 0x1101 is to right shift it. Thus b2>>=4;

    You can have your masks in any form, but it’s usual to have them in decimal as the powers of 2 (so that you can take any bit out of your byte) or decide what range you want on your variables and make the mask “larger” like 0x00000011, or ox00001100. Those 2 masks would respectively get you 2 values from a byte, each value ranging from 0 to 3, values that you can fit 4 inside a byte.

    for more info, chek out the relevant wiki.

    Sorry, the values were a little off (since byte seems to go from -128 to 127, but the idea is the same.

    Second edit (never used bitwise operations myself lol)… the “0x” notation is for hexadecimals. So you’ll actually have to calculate for yourself what 01001111 actually means… pretty sucky 😐 but it’s gonna do the trick.

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

Sidebar

Related Questions

Here's the problem. I ,for example,have a string 2500.Its converted from byte array into
I have a byte array that may or may not have null bytes at
I have a python method that returns a Python byte array.array('c'). Now, I want
I have a byte array containing bytes from a file( see my last question
I have a byte array, and I need to get four bytes from it
I have a byte array I want to assign as follows: First byte specifies
I have a method that currently returns a string converted from a byte array:
I have a method that currently returns a string converted from a byte array:
I want to convert a string into a byte array. (Yes) I have seen
I have a byte array that I am reading in from a NetworkStream. The

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.