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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:27:08+00:00 2026-06-18T12:27:08+00:00

I am working on a function that takes in a signal and adds it

  • 0

I am working on a function that takes in a signal and adds it into a vector.

Once enough signals have been added, in my case 4, then I loop through the vector and add it to an integer variable in my process.

I am having trouble converting the individual elements into integers.

I tried using to_integer(unsigned(myVector)), but this was a binary to decimal conversion.

I just want it so that when i loop through my vector like this:

for i in 0 to myVector'length loop
    Sum := Sum + to_integer(myVector(i));
end loop;

that a bit value of 1 or 0 gets converted to a 1 or 0 that I can use to add to my sum.

Any ideas?

Thanks

PS – myVector is a signal, Sum is an integer variable in my process.
If there is no simple way, how else can I do this?

  • 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-18T12:27:10+00:00Added an answer on June 18, 2026 at 12:27 pm

    Assuming you want to count the ones in a numeric_std_unsigned, the problem is simply that to_integer needs to work on a vector (an unsigned) while myVector(i) is a bit (std_logic)

    The following creates a 1-bit unsigned which to_integer should be happy with.

    for i in 0 to myVector'length loop
        Sum := Sum + to_integer(myVector(i downto i ));
    end loop;
    

    Alternatively, if the synthesis tool doesn’t like dynamically slicing myVector in a loop,

    for i in 0 to myVector'length loop
        if myVector(i) = '1' then
            Sum := Sum + 1;
        end if;
    end loop;
    

    will do.

    Also note that the loop bounds probably have a range error… 0 to length is probably 1 iteration more than you have elements – ASSUMING the elements actually started at 0, which is quite an assumption.

    for i in myVector'low to myVector'high loop
    

    is preferred…

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

Sidebar

Related Questions

I am working with datetime objects in python. I have a function that takes
I have a working PHP function that takes in latitude/longitude coordinates and a distance
I'm working on a function that takes filepaths and dices them up into smaller
Working on a function that takes lines of texts and turns them into an
I have been looking for an elegant way to write a function that takes
I'm working with a PHP function that takes a string and converts all of
Hey, I was working with a PHP function that takes multiple arguments and formats
Working on a simple helper function in PowerShell that takes a couple of parameters
I have calendar that is working fine. Here is the function that display the
I am working on a function that takes in a series of permission strings,

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.