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

can not encode negative bytes #2

Open
a-trzewik opened this issue May 20, 2021 · 0 comments
Open

can not encode negative bytes #2

a-trzewik opened this issue May 20, 2021 · 0 comments

Comments

@a-trzewik
Copy link

a-trzewik commented May 20, 2021

java.lang.ArrayIndexOutOfBoundsException: Index -23 out of bounds for length 45

at nl.minvws.encoding.Base45$Encoder.encode(Base45.java:74)
at nl.minvws.encoding.Base45$Encoder.encodeToString(Base45.java:98)

It is because in java bytes can be negative so the value ("see below") can be also negative

        for (int i = 0; i < wholeChunkLength;) {
            int value = src[i++] * ByteSize + src[i++];
            result[resultIndex++] = toBase45[value % BaseSize];
            result[resultIndex++] = toBase45[value / BaseSize % BaseSize];
            result[resultIndex++] = toBase45[value / (BaseSize * BaseSize) % BaseSize];
        }

see

https://mkyong.com/java/java-convert-bytes-to-unsigned-bytes/

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

1 participant