hustcc / hustcc/radix.js

Bug in Hex conversion

Open
#1 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
6
Forks
2
PR merge metrics
No merged PRs in 30d

Description

Hello @hustcc 👋

I using `radix.js version 0.0.1`. I wanted to convert a hex value to an octal. This is my code:
```
let hexValue = ans = undefined

hexValue = "1F4"
ans = radix.convent(hexValue, 16, 8);
console.log(ans)

// Output: 364
```

**ISSUE:**
The program outputs *octal value* `364`. But the actual octal value of hex 1F4 is `764`.

----

Then I modified my code this way:
```
let hexValue = ans = undefined

hexValue = "1F4"
hexValue = hexValue.toLowerCase() // [Modified line] Make uppercase hex letters to lowercase

ans = radix.convent(hexValue, 16, 8);
console.log(ans)

// Output: 764
```

Now this time the program prints out the expected output 👍. I also tested hex with the other radices. The issues exist with the following conversions:

* Hex => Octal
* Hex => Bin
* Hex => Dec

> Conclusion: So I think this issue will be fixed if you convert the hex letters to lowercase and then doing the conversion.


Thanks.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.