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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:14:11+00:00 2026-05-30T01:14:11+00:00

I’m developing a program for a uC that reads in a 40 byte bit

  • 0

I’m developing a program for a uC that reads in a 40 byte bit array via SPI. This 40 byte array is a test vector that’s compared against a ‘known good’ test vector, which is stored on an SD Card.

To find the anomalies/faults/errors, I XOR every byte of the received test vector with the stored data. This results in a bit array that has ‘1’s where the faults lie. I can find the position of these ‘1’s easily by using the following algorithm.

The trouble is storing the position of these ‘1’s. Currently, I’m using Variable Length Arrays but the support for these is broken in GCC4.2 and so I’m not sure how reliable they would be in AVR-GCC.

My next thought was to use malloc, but that’s usually discouraged in embedded systems. Should I just declare a unsigned char array of length 320 and store a ‘1’ when I find a bit set? Example: I find bits 4, 8, 10, 42 and 250 set in my bit array. I then set the corresponding elements to ‘1’ to indicate that there were ‘1’s detected at these positions. This would take up 320 bytes of my SRAM. Alternatively, I could declare the array as an int and store the actual position starting from the top of the array.

Why I need the position of bits set? The SD Card contains another file which has information that corresponds to the position in the bit array. So, if a fault is discovered at position 24, the program can go and read the file and display information about everything it knows that’s connected to position 24.

NOTE: Some may wonder whether I need to read in the entire test vector at once. That is indeed the case.

  • 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-30T01:14:13+00:00Added an answer on May 30, 2026 at 1:14 am

    If you know the upper bound on your storage and it’s not onerous, it’s usually better to simply create a fixed size array.

    As you stated, variable length array support is spotty in some implementations and totally unavailable in others. And malloc comes with added overhead, and includes the possibility that it may fail.

    I’d go for the non-variable-length fixed-size (static is, I think, a misleading term to use here) array.


    Now, as to whether you use a character array where each value specifies whether or not the equivalent bit is bad, or an integer array where each element is a sequential list of the bad bits is a different matter.

    For a start, I’d try to minimise data in the second case use by using a 16-bit value – whether that’s a short or an int in your implementation I don’t know.

    But, since you have 320 bits, an 8-bit char won’t work for bit position, so a 16-bit value is needed.

    Hence, for that second case, you’ll need to use 640 bytes rather than 320, for the worst case where every bit in the sample is bad. You can get away with not needing a bad-bit count by storing -1 values in the unused slots of this array.

    So the choices really are (for bad-bit positions of 42 and 314, for example):

    BytePos  BadBitFlag    or:     BytePos  BadBitPosition
    0..41    0                     0/1      42
    42       1                     2/3      314
    43..313  0                     4/5      -1
    314      1                     :
    315..319 0                     638/9    -1
    

    It really depends on the limits of storage.

    You have to calculate the data regardless of which method you choose, since you’re opting for char-based “bits” in the first solution, meaning that the XOR result will need to be expanded from a bit array in 40 bytes to a byte array in 320 bytes.

    If you’re going to process the list of bad bits a lot, and you can spare the extra storage, I’d opt for the second solution.

    If you’re either only going to process the list a few times, or memory is really tight, go for the first solution.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string

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.