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

Fix: Ensure correct hexadecimal representation for .toString('hex') and .toString(16) methods #61

Merged
merged 2 commits into from
Sep 11, 2023
Merged

Fix: Ensure correct hexadecimal representation for .toString('hex') and .toString(16) methods #61

merged 2 commits into from
Sep 11, 2023

Conversation

nnnoel
Copy link
Contributor

@nnnoel nnnoel commented Aug 31, 2023

Fixes #60

Root Cause

The original implementation of the toString method was designed to only handle numerical base representations. When a string-based representation like 'hex' was passed to the method, it was not recognized or processed, and the method defaulted to returning the decimal string representation of the number (base = 10)

Summary:

  • Enhanced the toString method to correctly handle string-based base representations, ensuring that .toString('hex') and .toString(16) return the expected hexadecimal format of the number.
  • Added a test case to validate the correct conversion of numbers to hexadecimal.

@mrousavy
Copy link
Member

mrousavy commented Sep 6, 2023

Hey, thanks for your PR this looks good!

- Check if the argument is a string representation for the base.
- Set base to 16 if the argument is "hex".
@mrousavy mrousavy merged commit 4474750 into margelo:main Sep 11, 2023
3 of 4 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.

.toString('hex') and .toString(16) not returning correct hexadecimal representation
2 participants