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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:00:50+00:00 2026-05-24T02:00:50+00:00

I have a problem which has been torturing for many hours. I need to

  • 0

I have a problem which has been torturing for many hours. I need to be able to find the first non-zero value in an array (taking into account that there might be zeroes afterwards).

So if:

A [0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 48, 24, 0, 0, 18, 9, 9, 7, 8, 0];

How do I set a variable say, int origin; equal to 9, such that A [origin] = 16?

My actual problem is more complex than this but that’s essentially a simplified version of what’s got me stuck. I’m actually working with a bluetooth device that outputs sectors of 512 bytes, however each byte in that sector represents different things. So I have made a for loop to extract byte number 224 which is the one i’m interested in, then I made an array of the value 224 for each sector. Although all the other bytes in the sector contain data, this particular byte doesn’t start transmitting until much later. Since I want to analyse the data I need to know in which sector it starts being useful. Hence, I have the question above. All this information is completely irrelevant to the question but i’ve provided it for background.

Furthermore, and if you really want to top yourself with an answer, i need to output the byte number 224 as “latitude”, byte number 225 as “longuitude” and byte 226 as “elevation” (for a GPS) as an xml format. Any ideas as to how i would output my three byte arrays to xml format? I have read they must be in string form first but that’s easy:

string [] Lat = new string [Sectors];
for (int i = 0, i < sectors; i++)
{
   Lat[i] = A[i].ToString();
}

In the end, I’d like this as a result.

<document>
    <point lat = "50.0" lon = "-60.5" ele = "605">
        <time> 16:54:08 </time>
    </point>
    <point .... etc
</document>

I hope I gave you enough information and I’d be helpful for ANY kind of help. cheers everyone! By the way, all the code should be in c# and I use visual c# 2010 express.

  • 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-24T02:00:51+00:00Added an answer on May 24, 2026 at 2:00 am

    You state “array” in the question, which makes it easier:

    int index = -1;    
    for(int i = 0 ; i < arr.Length ; i++)
    {
        if(arr[i] != 0)
        {
            index = i;
            break;
        }
    }
    

    Now if index is non-negative it is the index of the first non-zero. The value is then arr[index].

    If you need to read from a FileStream just loop over Read and repeat. There is a hack with unsafe code you can use to make it marginally faster if you need.

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

Sidebar

Related Questions

Problem: I have an address field from an Access database which has been converted
I have a problem with a string in C++ which has several words in
I'm struggling here with a problem: I have a controller questions which has action
I have a problem, which I do not seem to be able to solve...
I have a problem which requires me to parse several log files from a
I have a problem which I think is related to forward declarations, but perhaps
I have a very simple problem which requires a very quick and simple solution
I have a problem with an application which uses the same stored procedure over
I have a problem with a little .Net web application which uses the Amazon
I have a problem in my project with the .designer which as everyone know

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.