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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:23:37+00:00 2026-06-12T00:23:37+00:00

I am looking for a method that will enable me to get a range

  • 0

I am looking for a method that will enable me to get a range of bits. For example if I have the binary data

0 1 0 1 1 0 1 1 1 1 0 1 0 1 1 1 (2 bytes)

I might need to get data from range bit 3 to 9. In other words I would be interested in:

0 1 0 1 1 0 1 1 1 1 0 1 0 1 1 1

so in short I will like to construct the method:

 byte[] Read(byte[] data, int left, int right){ 

     // implementation
 }

so that if I pass the data new byte[]{91,215}, 3, 9 I will get byte[]{122} (note byte 91 and 215 = 0 1 0 1 1 0 1 1 1 1 0 1 0 1 1 1 and byte 122 = 1 1 1 1 0 1 0 same binary data as the example.

It would be nice if I could use the << operator on byte arrays such as doing something like:

  byte[] myArray = new byte[] { 1, 2, 3 };
  var shift = myArray << 2;

If you are interested to know why I need this functionality:

I am creating a project on a board and often need to read and write values to the memory. The cdf, sfr, or ddf (refereed to as chip definition file) contains information about a particular chip. That file may look like:

;     Name                            Zone      Address     Bytesize  Displaybase Bitrange
;     ----                            ----      -------     --------  ----------- --------

sfr = "SPI0_CONTROL"              , "Memory", 0x40001000,        4, base=16
sfr = "SPI0_CONTROL.SPH"          , "Memory", 0x40001000,        4, base=16,    bitRange=25-25
sfr = "SPI0_CONTROL.SPO"          , "Memory", 0x40001000,        4, base=16,    bitRange=24-24
sfr = "SPI0_CONTROL.TXRXDFCOUNT"  , "Memory", 0x40001000,        4, base=16,    bitRange=8-23
sfr = "SPI0_CONTROL.INT_TXUR"     , "Memory", 0x40001000,        4, base=16,    bitRange=7-7
sfr = "SPI0_CONTROL.INT_RXOVF"    , "Memory", 0x40001000,        4, base=16,    bitRange=6-6

Since I am reading a lot of variables (sometimes 80 times per second) I will like to have an efficient algorithm. I guess my approach would be that if the bytesize is 8 then I will create a long from those 8 bytes then use the << and >> operators in order to get what I need. if the bytesize if 4 then I will create an int and use the << and >> operators but How will I do it if I need to read 16 bytes though? I guess my question should been how to implement the << and >> operators on custom struct types.

  • 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-12T00:23:38+00:00Added an answer on June 12, 2026 at 12:23 am

    You need the BitArray class from System.Collections.

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

Sidebar

Related Questions

I’m looking for method that will return string representation of byte data just like
I'm looking for a method that will allow me to get the title of
I'm looking to see if I can design a HtmlHelper extension method that will
I'm looking for an implementation of java.util.Map that has a method that will return
I'm looking for a method or an event that would get fired when a
I am looking for a method to monitor a running program that I have
I'm looking for a method that will allow me to take two URL's and
Im looking for a function that will enable me to find a certain string
I'm looking for a method that will flatten a json hash into a flattened
I am looking for an external JAR or a method that will supply me

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.