komputing/KHex


Kotlin library to handle hexadecimal value representations

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    
	dependencies {
		implementation 'com.github.walleth:khex:1.1.5'
	}
	dependencies {
		implementation("com.github.walleth:khex:1.1.5")
	}
	<dependency>
	    <groupId>com.github.walleth</groupId>
	    <artifactId>khex</artifactId>
	    <version>1.1.5</version>
	</dependency>

                            
    libraryDependencies += "com.github.walleth" % "khex" % "1.1.5"
        
        

                            
    :dependencies [[com.github.walleth/khex "1.1.5"]]
        
        

Readme


CI

What is it?

KHex is a Kotlin multiplatform 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

GitHub Packages

This library is available through GitHub Packages.

badge badge

In order to use it, first include the GitHub Packages maven repository inside your project build.gradle.kts file:

repositories {
    maven {
        name = "komputing/KHex GitHub Packages"
        url = uri("https://maven.pkg.github.com/komputing/KHex")
        credentials {
            username = "token"
            password = "\u0039\u0032\u0037\u0034\u0031\u0064\u0038\u0033\u0064\u0036\u0039\u0061\u0063\u0061\u0066\u0031\u0062\u0034\u0061\u0030\u0034\u0035\u0033\u0061\u0063\u0032\u0036\u0038\u0036\u0062\u0036\u0032\u0035\u0065\u0034\u0061\u0065\u0034\u0032\u0062"
        }
    }
}

When 'username' could be anything and 'password' is an encoded access token for public access.

JitPack (JVM only!)

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

badge

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

repositories {
    maven { url="https://jitpack.io" }
}

Set it up

Include the modules inside your project:

dependencies {
    implementation("com.github.komputing.khex:<module>:<version>")
}

Where <version> can be either a release or <branch>-SNAPSHOT such as master-SNAPHOT.

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