Sample code for 30+ languages & platforms
Xbase++

Demonstrate Binary Data Encoding Methods

Demonstrates binary data encoding methods.

Note: This example requires Chilkat v9.5.0.64 or later.

Chilkat Xbase++ Downloads

Xbase++
LOCAL oBinData
LOCAL nOffset
LOCAL nNumBytes
LOCAL oSb

oBinData := CreateObject("Chilkat.BinData")

//  Append 10 bytes: 00, 01, 02, 03, 04, 05, 06, 07, 08, 09
oBinData:AppendEncoded("00010203040506070809", "hex")

//  Show that binData contains 10 bytes.
? "num bytes = " + Str(oBinData:NumBytes)

//  Get as base64
? "base64: " + oBinData:GetEncoded("base64")

//  Get a chunk of the binary data.
//  The 1st byte is at index 0.
//  The output should be "02030405"
nOffset := 2
nNumBytes := 4
? "chunk: " + oBinData:GetEncodedChunk(nOffset, nNumBytes, "hex")

//  Copy the bytes to a StringBuilder using the base64url encoding
oSb := CreateObject("Chilkat.StringBuilder")
oBinData:GetEncodedSb("base64url", oSb)
? "base64url: " + oSb:GetAsString()

//  Remove a chunk from the binary data
nOffset := 2
nNumBytes := 4
oBinData:RemoveChunk(nOffset, nNumBytes)
//  The bytes remaining are 00,01,06,07,08,and 09
? "after removing chunk: " + oBinData:GetEncoded("hex")

oBinData:destroy()
oSb:destroy()