Repository navigation
Commit 54d056d
authored
fix: prevent digit position overflow in OctalToBinary for large octal inputs (#7776)
* fix: use long digit position in OctalToBinary
digitPosition grew as an int and overflowed for octal inputs with 5 or more digits, so convertOctalToBinary(10000) returned a negative value instead of 1000000000000. Making it a long keeps the position exact for the full range the method can represent.
* test: cover OctalToBinary inputs with 5+ octal digits
Fails on the current implementation because digitPosition overflowed int; passes with the long fix.1 parent 9e216aa commit 54d056d
2 files changed
Lines changed: 11 additions & 1 deletion
File tree
- src
- main/java/com/thealgorithms/conversions
- test/java/com/thealgorithms/conversions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
35 | 45 | | |
0 commit comments