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

Feature/getset bits #211

Merged
merged 7 commits into from
Jan 14, 2025
Merged

Feature/getset bits #211

merged 7 commits into from
Jan 14, 2025

Conversation

DimitryP6
Copy link
Contributor

Changes

Added macros for setting and getting bits of various types

Notes

If setting a bit results in an overflow (bit position is higher than available indices in given number), will just return number instead

Test Cases

Following test cases passed:
void test_get_bit() {

uint8_t byte_8 = 0b10101010;
uint16_t byte_16 = 0x1A2B;
GET_BIT(byte_8, 0);  // Should be 1
GET_BIT(byte_16, 12);  // Should be 1

}

void test_set_bit() {

uint8_t byte = 0b00000000;
SET_BIT(byte, 3);  // Now should be 0b1000 

uint16_t hex = 0x0000;
SET_BIT(hex, 15);  // Now should be 0x8000

}

To Do

Any remaining things that need to get done

  • item 1
  • ...

Checklist

It can be helpful to check the Checks and Files changed tabs.
Please reach out to your Project Lead if anything is unclear.
Please request reviewers and ping on slack only after you've gone through this whole checklist.

  • [* ] All commits are tagged with the ticket number
  • [ *] No merge conflicts
  • [* ] All checks passing
  • [ *] Remove any non-applicable sections of this template
  • [ *] Assign the PR to yourself
  • [ *] Request reviewers & ping on Slack
  • [* ] PR is linked to the ticket (fill in the closes line below)

Closes #200

@DimitryP6 DimitryP6 self-assigned this Dec 2, 2024
@DimitryP6 DimitryP6 requested a review from jr1221 December 2, 2024 00:05
Copy link
Contributor

@jr1221 jr1221 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the ema filter from this PR. Also one litttle thing to change (It was broken before your PR, see comment).

#define NER_SET_BIT(num, bit) \
bit < (sizeof(num) * 8) ? (num |= (1UL << bit)) : num

#endif /* C_UTILS */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put endif at the end of the file

#include <stdio.h>

// Exponential Moving Average Lowpass Filter
void ema_filter(float current_value, float *previous_ema, float alpha)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should only appear in ur other PR.

@DimitryP6 DimitryP6 requested a review from jr1221 January 9, 2025 17:47
Copy link
Contributor

@jr1221 jr1221 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm:)

@DimitryP6 DimitryP6 merged commit 07a22e3 into main Jan 14, 2025
2 checks passed
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.

[Utils] - Add get/set bit utils
2 participants