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

Supports numbers of different bases #219

Closed
wants to merge 3 commits into from
Closed

Supports numbers of different bases #219

wants to merge 3 commits into from

Conversation

ihaiker
Copy link

@ihaiker ihaiker commented Oct 24, 2023

No description provided.

@ihaiker ihaiker requested a review from abice as a code owner October 24, 2023 06:54
@ihaiker
Copy link
Author

ihaiker commented Oct 26, 2023

@abice Please check out my PR

B6 = 0b110
B7 = 0b111
B8 = 0x08
B9 = 0x09
Copy link
Owner

Choose a reason for hiding this comment

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

Can you add some values in here that contain non standard hex values (letters, specifically)

Copy link
Author

Choose a reason for hiding this comment

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

I support not only hexadecimal values, but also binary and octal values.

Copy link
Owner

Choose a reason for hiding this comment

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

Right, just make sure that 0x0f and 0xff parse correctly into the right values.

Copy link
Author

Choose a reason for hiding this comment

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

Already added

Comment on lines +533 to +535
} else if strings.HasPrefix(value, "0") && len(value) > 1 {
return value[1:], 8
}
Copy link
Owner

@abice abice Nov 6, 2023

Choose a reason for hiding this comment

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

I'm not sure I understand the benefit of this case. Do you mind elaborating a bit on why you would want this?

And what happens when you specify a value larger than the max?

Copy link
Author

Choose a reason for hiding this comment

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

My intention is to support different representations of values in different binaries, in my project I usually use hexadecimal identifiers for these numbers, and if I convert to decimal for these values, it would be a problem to read the code. Of course, I could add comments to it and state the given value in the comments, but it feels like I'm adding to the problem.

Copy link
Author

Choose a reason for hiding this comment

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

0XX is the number written in the base of the eight.

Copy link
Owner

@abice abice left a comment

Choose a reason for hiding this comment

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

Left a comment on this one a while ago about adding a extra test case.

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