Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update HX711_ADC.cpp #52

Merged
merged 1 commit into from
Oct 20, 2020
Merged

Conversation

MalcolmBoura
Copy link
Contributor

Efficiency and code size improvement.
The first term in most of the if statements was redundant anyway due to the preceding if but the daisy chain of if can be dispensed with completely.
Tested out of context with
#include <stdio.h>

void calculate(int samples)
{
int divBit;

printf("%d ", samples);
samples >>= 1;
for(divBit = 0; samples != 0; samples >>= 1, divBit++);
printf("%d %d\n", 1 << divBit, divBit);

}

int main()
{
calculate(3);
calculate(7);
calculate(8);
}

Efficiency and code size improvement.
The first term in most of the if statements was redundant anyway due to the preceding if but the daisy chain of if can be dispensed with completely.
Tested out of context with
#include <stdio.h>

void calculate(int samples)
{
    int divBit;
    
    printf("%d ", samples);
    samples >>= 1;
    for(divBit = 0; samples != 0; samples >>= 1, divBit++);
    printf("%d %d\n", 1 << divBit, divBit);
}

int main()
{
    calculate(3);
    calculate(7);
    calculate(8);
}
@olkal
Copy link
Owner

olkal commented Oct 20, 2020

I had to look over your code a number of times to understand how it worked, but in the end I got it. Very neat.
Thank you, much appreciated!

@olkal olkal merged commit 3d07c03 into olkal:master Oct 20, 2020
@MalcolmBoura
Copy link
Contributor Author

MalcolmBoura commented Oct 20, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants