Skip to content

Incorrect output in toHexString applied to Byte and Short values #10216

@scabug

Description

@scabug

This is my very first issue submission to Scala, so I apologize in advance for any mistakes I might have made in filling out the different fields.

Calling toHexString method on numeric types other than Int will produce unexpected output. I believe that toHexString is not implemented in Byte and Short and an implicit conversion to Int is happening.

scala> -1.toByte.toHexString
res2: String = ffffffff
// should be "ff"

scala> -1.toShort.toHexString
res3: String = ffffffff
// should be "ffff"

scala> -1.toHexString
res4: String = ffffffff
// is correct

scala> -1.toLong.toHexString
res5: String = ffffffffffffffff
// is correct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions