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

Add ability to convert between number bases #1

Open
tuhdo opened this issue May 19, 2014 · 3 comments
Open

Add ability to convert between number bases #1

tuhdo opened this issue May 19, 2014 · 3 comments

Comments

@tuhdo
Copy link

tuhdo commented May 19, 2014

It would be nice if we are able to quickly convert between base 2, base 8 and base 16 on a number at point..

@knu
Copy link
Owner

knu commented May 19, 2014

It currently supports one way conversion from a decimal number, to base 2, 8 and 16.
https://github.com/knu/operate-on-number.el/blob/master/operate-on-number.el#L100-L103

Do you mean you want to convert a base 2/8/16 number at point to a decimal number? What prefixes/suffixes should it deal with, like 0x-, \x-, or -h?

@tuhdo
Copy link
Author

tuhdo commented May 19, 2014

Hex prefixes: 0x (in C), #x (in Emacs Lisp), # (in CSS).
Octal: In C, octal number is prefixed with 0, i.e. 0123 is 123 in octal.

I think if a number has the above prefixes, then it is fine for automatic conversion. If supply with prefix argument, users are asked for target base to convert to . In case of unable to identify the base, user is prompted to enter the number base and a target base to convert; then, operate-on-number convert to that base accordingly. By default, the target base should be decimal if user leaves the target base blank.

@knu
Copy link
Owner

knu commented May 27, 2014

To implement this properly, we must work out a way to detect the format to make sure it is kept after an operation: e.g. Incrementing 0x000f should result in 0x0010 instead of 16 or f.

By the way, I'm not sure if we should support zero-prefixed octal numbers by default. There are a bunch of zero-filled decimal and hexadecimal numbers out there.

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

No branches or pull requests

2 participants