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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:53:16+00:00 2026-06-10T14:53:16+00:00

Is there a way to convert an array to an integer, i have the

  • 0

Is there a way to convert an array to an integer, i have the follow method but it does not seem to work:

int8_t x_array[18] = {0,1,1,0,1,0,1,0,1,0,1,0,0,0,0,0,1,1};
int32_t numb;

for (int8_t j=0;j<19;j++)
{
   numb = numb + pow(2, i)*x_array[i];
}

Is there a reason for this??

PS: this is a follow up question from a previous question I had posted
Joining outputs from switches
I have edited the question to say why the method suggested is not working.

In essence what I am trying to do is create a program, in RAPIDILITTE which is a simulator software, to sample a PS input (proximity sensor system) every millisecond which is 18-bit digital input. The input is represented by toggle switches 0-17(18-bits) which is located on port 2. the input need to be normalised between 0-9999)

The main problem is that( which I have mentioned in the previous posted question) I can only access one pin at a time and not the read the whole port at once. I have tried many ways to read the pins and combine them into one variable convert it to a natural number and then normalise the input. In the end I believe the best way to do this is to put the each pins reading into a array[18] and then covert this into a variable and then normalise it.

  • 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-10T14:53:17+00:00Added an answer on June 10, 2026 at 2:53 pm

    numb is never initialized. You’re also iterating past the last element in the array (j < 19 should be j< 18). Additionally, you never declared i… it appears you meant j.

    I believe you’re trying to convert the array of bits into a single int32_t. Presumably the array is in ascending order of significance i.e. from least- to most-significant bit.

    int8_t x_array[18] = { 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1 };
    int32_t numb = 0;
    for (int8_t j = 0; j < 18; ++j) {
      numb |= x_array[j] << j;
    }
    

    You don’t need to use pow here, since pow(2, j) is equivalent to 1 << j.

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

Sidebar

Related Questions

Simple question here: is there any way to convert from a jagged array to
Is there a way to convert an integer to a string in PHP?
I have an integer array: a=[3,4,5,6,7]; I want to convert it to a binary
I have method for converting array of Booleans to integer. It looks like this
I'd like to convert an array of integer values I have received over USB
Is there a way to convert a multidimensional array to a stdClass object in
In Java, I have an array of integers. Is there a quick way to
Is there a way to convert twitter bootstrap's typeahead function into a $(body).on() function?
Is there any way to convert a android.graphics.Bitmap instance into jpeg in android?
Is there a way to convert a Java application into a Mac OS X

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.