Hex
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kaigouthro

//@version=5    
//@description Hex String Utility
library('Hex')

// @function helper Binary half octet to hex character
// @param    _n Digits to convert  
export intToHex(int _n) =>
    switch _n
        0  => '0'
        1  => '1'
        2  => '2'
        3  => '3'
        4  => '4'
        5  => '5'
        6  => '6'
        7  => '7'
        8  => '8'
        9  => '9'
        10 => 'A'
        11 => 'B' 
        12 => 'C'
        13 => 'D'
        14 => 'E'
        15 => 'F'    
        => '%ERROR'

// @function  Digits to Hex String output
// @param     _input  Integer Input
// @param     _buffer Number of 0's to pad Hex with
// @returns   string  output hex character value buffered to desired length (00-ff default)
export fromDigits (int _input, int _buffer = 2) =>
    _dec = _input
    _out = ''
    switch _input 
        0 => _out := '00'
        =>
            while _dec > 0
                _n   = _dec/16 
                _f   = math.floor(_n)
                _r   = (_n -_f ) * 16
                _out := intToHex(_r)  + _out
                _dec := _f
            while str.length(_out )%_buffer > 0
                _out := '0'+_out
    _out


// Demo
if barstate.islastconfirmedhistory
    c = 0    
    a = ''    
    for i = 0 to 255
        c+=1
        a += fromDigits(i*1000,8)
        a +=' \n'
        
        if (i+1) % 16== 0
            label lb = na
            label.delete(lb[1])
            lb := label.new(last_bar_index-i, close,a,size=size.huge,color=color.white,size=size.tiny)
            c:=0
    
    