Skip to content

can not encode negative bytes #2

@a-trzewik

Description

@a-trzewik

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/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions