Skip to content
/ KHex Public
forked from komputing/KHex

Kotlin library to handle hexadecimal value representations

License

Notifications You must be signed in to change notification settings

z-chu/KHex

This branch is 12 commits behind komputing/KHex:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

a325530 · Dec 4, 2019

History

33 Commits
Dec 4, 2019
Dec 4, 2019
Dec 4, 2019
Dec 4, 2019
Dec 4, 2019
Dec 4, 2019
Jul 15, 2017
Dec 4, 2019
Dec 4, 2019
Dec 4, 2019
Dec 4, 2019
Dec 4, 2019
Dec 4, 2019

Repository files navigation

What is it?

KHex is a Kotlin library to deal with hexadecimal encoding and decoding.

It was incubated as part of KEthereum but then extracted as it can be useful outside this context.

Get it

This library is available on Jitpack. The current version is:

In order to use it, first of all include the Jitpack maven repository inside your project build.gradle file:

repositories {
    maven { url 'https://jitpack.io' }
}

Then, include the modules inside your project:

dependencies {
    implementation 'com.github.komputing.khex:<module>:<version>'
}

Available modules

Module Description
core Contains the core code
extensions Contains useful extension functions

Usage

As a function

You can use the functions contained inside this library in order to encode or decode any hexadecimal value.

// Encoding

val myByteValue = 31.toByte()
encode(myByteValue)

val myByteArrayValue = byteArrayOf(31, 32 , 33)
encode(myByteArrayValue)


// Decoding

val myHexString = "0xaa12456789bb"
decode(myHexString)

As extension functions

By including the extensions module, you will be able to access a list of extensions functions that can be useful when working with strings and byte arrays/lists.

// ByteArray
byteArrayOf(1, 2, 3).toHexString(prefix = "0x")
byteArrayOf(1, 2, 3).toNoPrefixHexString()

// List<Byte>
listOf(1.toByte(), 2.toByte()).toHexString(prefix = "0x")
listOf(1.toByte(), 2.toByte()).toNoPrefixHexString()

// StringHexString("0xaa12456789bb").hexToByteArray()
HexString("0xaa12456789bb").has0xPrefix()
HexString("aa12456789bb").prepend0xPrefix()
HexString("0xaa12456789bb").clean0xPrefix()

License

MIT

About

Kotlin library to handle hexadecimal value representations

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 100.0%