Bitwise, Encode, Decode
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © FFriZz

frizlabz =
 "\n 
	      ███████╗███████╗██████╗ ██╗███████╗███████╗
	  	  ██╔════╝██╔════╝██╔══██╗██║╚══███╔╝╚══███╔╝
	      █████╗  █████╗  ██████╔╝██║  ███╔╝   ███╔╝ 
	  	  ██╔══╝  ██╔══╝  ██╔══██╗██║ ███╔╝   ███╔╝  
	      ██║     ██║     ██║  ██║██║███████╗███████╗
	     '█████╗████╗ █╗████╗ █╗'╝╚═'███╗ ████╗ ████╗ 
         '██╔═══█╔══█╗█║╚══█║ █║    █╔══█╗█╔══█╗╚══█║
         '████╗ ████╔╝█║  █╔╝ █║    █████║████╔╝  █╔╝
         '██╔═╝ █╔══█╗█║ █╔╝  █║    █╔══█║█╔══█╗ █╔╝ 
         '██║   █║  █╗█║█╔╝   █║    █║  █║█║  █║█╔╝  
         '██║   █║  █║█║█████╗█████╗█║  █║████║ ████╗
         '╚═╝   ╚╝  ╚╝╚╝╚════╝╚════╝╚╝  ╚╝╚═══╝ ╚═══╝
          
 				 Decode, Encode, Binary(bitwise)  Library
   Import the Library and Call docs() use hoverover to see Docs in Editor! 
	 		 
			   import FFriZz/Bitwise/1 as bit 
	 		   bit.docs()
 "


// Refrences to Read
// https://en.wikipedia.org/wiki/Bitwise_operation
// https://byjus.com/maths/binary-number-system/#:~:text=A%20binary%20number%20system%20is,2%20is%20a%20binary%20number.


// @description Bitwise, Encode, Decode, and more Library
// The bitwise functions library offers a range of tools for performing bitwise operations that are not
// available in Pinescript. 
// These operations can be particularly useful in optimizing storage and indexing in specific 
// applications by combining two integers into one. 
// For instance, encoding the row and column location of a matrix into 
// a single array index can expedite the indexing process by accessing only one array index.
// 
// It's important to note that binary numbers are referenced from right to left. 
// Therefore, keeping the encoded integers within the 32-bit system range 
// is crucial for effectively utilizing this technique. 
// As a rule of thumb, the sum of the two integers being encoded should not exceed 65535. 
// This ensures that the resulting encoded integer can fit within a 32-bit number with 2 16-bit integers, 
// 
// The library includes both an encoding function, 
// which accepts two integers and returns a single encoded integer, 
// and a decoding function, which accepts the encoded integer and returns the two original integers. 
// and many more potential permormance tools.
// It's worth noting that while it's possible to encode multiple integers together, 
// this can become impractical due to the rounding up of numbers past 16 digits in Pinescript.
// 
// Overall, the bitwise functions library provides 
// a valuable tool for optimizing storage and indexing in specific applications. 
// By utilizing bitwise operations to encode 2 integers into a single value, 
// it's possible to significantly improve the efficiency of certain algorithms and processes.



//@version=5
library("Bitwise")
// import FFriZz/FrizBug/14 as p



// Bitwise operator psudo functions [<<, >>, &, ^, |, ~]
// -----------------------------------------------------
// @function Returns the bitwise AND of two integers [&]
// @param a `int` - The first integer
// @param b `int` - The second integer
// @returns `int` - The bitwise AND of the two integers
export method  bAnd(int a,int b) =>
	_a=a, _b=b
    result = 0
    bit = 1
    while _a > 0 and _b > 0
        if (_a % 2) == 1 and (_b % 2) == 1
            result += bit
        bit *= 2
        _a := math.floor(_a / 2)
        _b := math.floor(_b / 2)
    result

// @function Performs a bitwise OR operation on two integers. [|]
// @param a `int` - The first integer.
// @param b `int` - The second integer.
// @returns `int` - The result of the bitwise OR operation.
export method  bOr(int a,int b) => 
	_a=a, _b=b
    bit = 1
    result = 0
    while _a > 0 or _b > 0
        if (_a % 2) == 1 or (_b % 2) == 1
            result += bit
        bit *= 2
        _a := math.floor(_a / 2)
        _b := math.floor(_b / 2)
    result

// @function Performs a bitwise Xor operation on two integers. [^]
// @param a `int` - The first integer.
// @param b `int` - The second integer.
// @returns `int` - The result of the bitwise Xor operation.
export method  bXor(int a,int b) =>
	_a=a, _b=b
    bit = 1
    result = 0
    while _a > 0 or _b > 0
        if (_a % 2) != (_b % 2)
            result += bit
        bit *= 2
        _a := math.floor(_a / 2)
        _b := math.floor(_b / 2)
    result

// @function Performs a bitwise NOT operation on an integer. [~]
// @param n `int` - The integer to perform the bitwise NOT operation on.
// @returns `int` - The result of the bitwise NOT operation.
export method bNot(int n) => bXor(n, -1)

// @function Performs a bitwise left shift operation on an integer. [<<]
// @param n    `int` - The integer to perform the bitwise left shift operation on.
// @param step `int` - The number of positions to shift the bits to the left.
// @returns `int` - The result of the bitwise left shift operation.
export method bShiftLeft(int n, int step) =>
    // Check if the step is negative or too large
    out = if step < 0 or step > 31
        // Invalid step, return an error value
        int(0)
    else
        // Perform the bitwise shift
        result = n * math.pow(2, step)
        // Handle overflow
        if result > 2147483647
            result := -(4294967296 - result)
        int(result)
    out
// bShiftLeft(48765,6).print("\n\nbShiftLeft(48765,6)",pos="3",text_size="normal")

// @function Performs a bitwise right shift operation on an integer. [>>]
// @param n    `int` - The integer to perform the bitwise right shift operation on.
// @param step `int` - The number of bits to shift by.
// @returns `int` - The result of the bitwise right shift operation.
export method bShiftRight(int n, int step) =>
    if step >= 0
        int(math.floor(n / math.pow(2, step)))
    else
        int(bShiftLeft(n, -step))
// bShiftRight(48765,28).print(pos="7")

// @function Performs a bitwise right shift operation on an integer. 
// @param n    `int` - The int to perform the bitwise Left rotation on the bits.                        
// @param step `int` - The number of bits to shift by.
// @returns    `int`- The result of the bitwise right shift operation.
export method bRotateLeft(int n,int step) =>
    _step = step
    bits = 32
    _step %= bits
    bOr(bShiftLeft(n,_step),bShiftRight(n,bits-_step))
// bRotateLeft(48765,28).print(pos="4")

// @function Performs a bitwise right shift operation on an integer.
// @param n    `int` - The int to perform the bitwise Right rotation on the bits.
// @param step `int` - The number of bits to shift by.
// @returns `int` - The result of the bitwise right shift operation.   
export method bRotateRight(int n, int step) =>
    _step = step
    bits = 32
    _step %= bits
    bOr(bShiftRight(n,_step), bShiftLeft(n,bits -_step))
// bRotateRight(48765,24).print(pos="1")




// @function Checks if the bit at the given position is set to 1.
// @param n   `int` - The integer to check.
// @param pos `int` - The position of the bit to check.
// @returns `bool` - True if the bit is set to 1, False otherwise.
export method bSetCheck(int n, int pos) => bAnd(n,bShiftLeft(1,pos)) > 0
// str.format("\n4={0}\n7={1}",bSetBit(48765,4),bSetBit(48765,7)).print(pos="4")                  
// 10111110 0 11 1 1101


// @function Clears a particular bit of an integer (changes from 1 to 0) passes if bit at pos is 0.
// @param n    `int` - The integer to clear a bit from.
// @param pos  `int` - The zero-based index of the bit to clear.
// @returns `int` - The result of clearing the specified bit.
export method bClear(int n,int pos) =>
    _n = n
    if bSetCheck(n,pos)
        mask = math.floor(math.pow(2, pos))
        _n -= mask
    _n
// bClear(48765,3).print(pos="2") 
// 101111100111 1 101  =  101111100111 0 101
//       48765                  48757


// @function Flips all 0 bits in the number to 1.
// @param n `int` - The integer to flip the bits of.
// @returns `int` - The result of flipping all 0 bits in the number.
export method bFlip0s(int n) => bNot(n)
// bFlip0s(3365).print(pos="7") 
// 110100100101  =  111111111111
//    3365              4095


// @function Flips all 1 bits in the number to 0.
// @param n `int` - The integer to flip the bits of.
// @returns `int` - The result of flipping all 1 bits in the number.
export method bFlip1s(int n) => n*0
// bFlip1s(3365).print(pos="9") 
// 110100100101  =  000000000000
//    3365               0


// @function Flips all bits in the number.
// @param n `int` - The integer to flip the bits of.
// @returns `int` - The result of flipping all bits in the number.
export method bFlipAll(int n) =>
    result = 0
    bit = 1
    _n = n
    while _n > 0
        if (_n % 2) == 0
            result += bit
        bit *= 2
        _n := math.floor(_n / 2)
    result
// bFlipAll(5565).print("\n\nbFlipAll(5565)",pos="2",text_size="normal")
// 1 0 1 0 11 0 1111 0 1  =  0 1 0 1 00 1 0000 1 0
//         5565                      2626


// @function Changes the value of the bit at the given position.
// @param n      `int` - The integer to modify.
// @param pos    `int` - The position of the bit to change.
// @param newBit `int` - na = flips bit at pos reguardless 1 or 0 | The new value of the bit (0 or 1).
// @returns `int` - The modified integer.
export method bSet(int n,int pos,int newBit=na) =>
    _n = n
    _newBit = newBit
    if na(newBit)
        if bSetCheck(n,pos)
            _newBit := 0
        else
            _newBit := 1
    if _newBit < 1
        mask = math.floor(math.pow(2, pos))
        if bAnd(_n,mask) > 0
            _n -= mask
    else if _newBit >= 1
        mask = math.floor(math.pow(2, pos))
        if bAnd(_n,mask) == 0
            _n += mask
    _n
// bSet(48765,4,0).print("\n\nbSet(48765,4,0)",pos="7",text_size="normal")
// 10111110011 1 1101 = 10111110011 0 1101
//           48765                48749


// @function Changes the value of the digit at the given position.
// @param n        `int` - The integer to modify.
// @param pos      `int` - The position of the digit to change.
// @param newDigit `int` - The new value of the digit (0-9).
// @returns `int` - The modified integer.
export method changeDigit(int n,int pos,int newDigit) =>
    digits = array.new_int(0)
    temp = n
    while temp > 0
        digit = temp % 10
        digits.push(digit)
        temp := math.floor(temp / 10)
    digits.set(pos, newDigit)
    result = 0
    multiplier = 1
    for i = 0 to digits.size() - 1
        result := result + (digits.get(i)*multiplier)
        multiplier := multiplier * 10
    result                            
// changeDigit(48765,3,13).print(pos="5") 
//        
// 4 8 765 = 53 765  
                                           

// @function Switch the position of 2 bits of an int
// @param n `int` - int to manipulate
// @param i `int` - bit pos to switch with j
// @param j `int` - bit pos to switch with i
// @returns `int` - new int with bits switched 
export method bSwap(int n, int i, int j) =>
    num = n
    int bit_i = bAnd(bShiftRight(num,i),1)
    int bit_j = bAnd(bShiftRight(num,j),1)
    if bit_i != bit_j
        num := bXor(num,bOr(bShiftLeft(1,i),bShiftLeft(1,j)))
    num                                      
// bSwap(48765,6,14).print("\n\nbSwap(48765,6,14)",pos="1",text_size="normal") 
// 48765 = 1 0 1111100 1 111101 | 65085 = 1 1 1111100 0 111101
//           ^         ^                    ^         ^
                                      

// @function Checks to see if the binary form is a Palindrome (reads the same left to right and vice versa)
// @param n `int` - int to check
// @returns `bool` - result of check 
export method bPalindrome(int n) =>
    int rev = 0
    int temp = n
    while temp > 0
        rev := bOr(bShiftLeft(rev,1),bAnd(temp,1))
        temp := bShiftRight(temp,1)
    n == rev
// bPalindrome(5).print(pos="7") // 101
// bPalindrome(48765).print(pos="8") // 10111110|01111101
// bPalindrome(48764).print(pos="9") // 1011111001111100


// @function Checks if n is Even
// @param n `int` - The integer to check.
// @returns `bool` - result.
export method bEven(int n) => bAnd(n, 1) == 0
// bEven(64).print("\n\nbEven(64)",pos="4",text_size="normal")


// @function checks if n is Even if not even Odd
// @param n `int` - The integer to check.
// @returns `bool` - result.
export method bOdd(int n) => bAnd(n, 1) != 0
// bOdd(64).print("\n\nbOdd(64)",pos="5",text_size="normal")


// @function Checks if n is a Power of 2.
// @param n `int` - number to check.
// @returns `bool` - result.
export method bPowerOfTwo(int n) => bAnd(n, (n - 1)) == 0 and n > 0
// str.format("64={0}\n62={1}",bPowerOfTwo(64),bPowerOfTwo(62)).print(pos="5")


// @function Counts the number of bits that are equal to 1 in an integer.
// @param n `int` - The integer to count the bits in.
// @returns `int` - The number of bits that are equal to 1 in n.
export method bCount(int n,string to_count="all") =>
    grab = false
    _count = 0
    _to = switch to_count 
        "all" => grab := true
        "1"   => _count := 1
        "0"   => _count := 0 
    _n = n
    count = 0
    while _n > 0
        if _n % 2 == _count
            count +=1
        else if grab
            count +=1
        _n := math.floor(_n / 2)
    count
// bCount(48765).print("\n\nbCount(48765)",pos="8",text_size="normal")



// @function Finds the greatest common divisor (GCD) of two numbers.
// @param a `int` - The first number.
// @param b `int` - The second number.
// @returns `int` - The GCD of a and b.
export method GCD(int a, int b) =>
    _a = a, _b = b
    while _b > 0
        temp = _b
        _b := _a % _b
        _a := temp
    _a
// GCD(5,25).str()print("5")

// @function Finds the least common multiple (LCM) of two integers.
// @param a `int` - The first integer.
// @param b `int` - The second integer.
// @returns `int` - The LCM of a and b.
export method LCM(int a, int b) =>
    (a * b) / GCD(a, b)
// LCM(5,84).str()print("2")

// @function Finds the LCM of an array of integers.
// @param nums `int[]` - The list of integers.
// @returns `int` - The LCM of the integers in nums.
export method aLCM(array<int> nums) =>
    result = nums.get(0)
    for i = 1 to nums.size()-1
        result := LCM(result, nums.get(i))
    result
// aLCM(array.from(55,43,80)).str()print("3")

// @function adjust an array of integers to Least Common Multiple (LCM)
// @param nums `int[]` - The first integer
// @param LCM `int` - The second integer
// @returns int[] - array of ints with LCM
export method adjustedLCM(array<int> nums,int LCM) =>
    for i in nums
        nums.unshift(((nums.pop()/LCM)*100000)/5)
    nums



// @function gets a Char at a given position.
// @param str `string` - string to pull char from.
// @param pos `int` - pos to get char from string (left to right index).
// @returns `string` - char from pos of string or "" if pos is not within index range
export method charAt(string str, int pos) =>
    len = str.length(str)
    if pos >= 0 and pos < len 
        str.substring(str, pos, pos+1)
    else
        ""
//charAt("FrizLabz",3).print(pos="8")
//           3 == z


// @function Converts a decimal number to binary
// @param num  `int` - The decimal number to convert to binary
// @returns `string` - The binary representation of the decimal number
export method decimalToBinary(int num) =>
    _num = num
	binary = ""
    while _num > 0
        binary := str.tostring(_num%2)+binary
        _num := math.floor(_num/2)
    binary

// @function Converts a decimal number to binary
// @param num             `int` - The decimal number to convert to binary
// @param to_binary_int  `bool` - bool to convert to int or to string (true for int, false for string)
// @returns `string` - The binary representation of the decimal number
export method decimalToBinary(int num=na,bool to_binary_int=true) => 
    to_binary_int ? int(str.tonumber(decimalToBinary(num))) : na


// @function Converts a binary number to decimal
// @param binary `string` - The binary number to convert to decimal
// @returns `int` - The decimal representation of the binary number
export method binaryToDecimal(string binary) =>
	decimal = 0.0
    for [n,i] in str.split(binary,"")
        if i == "1"
            decimal += math.pow(2,str.length(binary)-1-n)
    int(decimal)

export method binaryToDecimal(int binary) =>
    binaryToDecimal(str.tostring(binary))


// @function way of finding decimal length using arithmetic 
// @param x `float` - value to find number of decimal places
// @returns `int` - number of decimal places 
export method decimal_len(float n) => 
    var count = 0
    var _n = math.abs(n)
    var carry = int(_n)
    _n -= carry
    while _n != int(_n)
        _n *= 10
        count += 1
        if count > 10
            break
    count
// decimal_len(0.55523235).print(pos="3") // 8


// @function way of finding number length using arithmetic 
// @param n `int`- value to find length of number
// @returns `int` - lenth of nunber i.e. 23 == 2
export method int_len(int n) => 
	x = 1
	count = 0
	while (n - x) > 0
		x *= 10
		count += 1
	count
// int_len(555422222).print() //9


// @function Converts a float decimal number to an integer `0.365 to 365`.
// @param n `string` - The decimal number represented as a string.
// @returns `int` - The integer obtained by removing the decimal point and leading zeroes from s.
export method float_decimal_to_whole(float n) => 
    str.tonumber(str.split(str.tostring(n),'.').get(1))
// float_decimal_to_whole(0.4545).print(pos="9") // 4545


// @function Returns the fractional part of a float.
// @param x `float` - The float to get the fractional part of.
// @returns `float` - The fractional part of the float.
export method fractional_part(float x) => 
    x - math.floor(x)
// fractional_part(48765.6656).print(pos="6") //0.6656


// @function helper to form 2 ints into 1 float seperated by the decimal
// @param a `int` - a int
// @param b `int` - b int
// @param zero_fix `bool` - fix for trailing zeros being truncated when converting to float
// @returns [decimal,convert] - decimal = decimal of ints | convert = string version of last for future use to ref length
export method form_decimal(int a,int b,bool zero_fix=false) =>
	convert = str.tostring(b)
	dec = a+str.tonumber("0."+convert+(zero_fix?'1':''))
	[dec,str.length(convert)]
// [dec,_] = form_decimal(212,696)
// dec.print(pos="2") //212.696




// @function Encodes two numbers into one using bit OR. (fastest)
// @param n1 `int` - The first number to Encodes.
// @param n2 `int` - The second number to Encodes.
// @returns `int` - The result of combining the two numbers using bit OR.
export method bEncode(int n1, int n2) => bOr(n1,bShiftLeft(n2,16))
// _number_ = bEncode(44,785).print("\n\nbEncode(44,785)",pos="9",text_size="normal")

// @function Decodes an integer created by the bCombine function.(fastest)
// @param n `int` - The integer to decode.
// @returns `[int, int]` - A tuple containing the two decoded components of the integer.
export method bDecode(int n) => [n%65536, math.floor(n/65536)]
// [_n1_,_n2_] = bDecode(_number_)
// str.format("[{0}, {1}]",_n1_,_n2_).print("\n\nbDecode(bEncode(44,785))",pos="6",text_size="normal")


// @function Encodes by seperating ints into left and right of decimal float
// @param a `int` - a int
// @param b `int` - b int
// @returns `float` - new float of encoded ints one on left of decimal point one on right
export method Encode(int a, int b) => 
	[_a,_] = a.form_decimal(b,true)
	_a
// En = Encode(232,97).print(pos="5") // 232.971

// @function Decodes float of 2 ints seperated by decimal point
// @param encoded `float` - the encoded float value
// @returns `[int, int]` - tuple of the 2 ints from encoded float
export method Decode(float encoded) =>
	a = int(encoded)
	_b = str.tostring(encoded-a)
	b = str.tonumber(str.substring(_b,2,str.length(_b)-1))
	[a,b]
// [__a,__b]= Decode(En) // 232,97	
// str.format("\na={0}\nb={1}\n",__a,__b).print(pos="6")


// @function Encodes by combining numbers and tracking size in the
// decimal of a floating number (slowest)
// @param a `int` - a int
// @param b `int` - b int
// @returns `float` - new decimal of encoded ints
export method encode_heavy(int a,int b) =>
	[dec,len] = a.form_decimal(b)
	factor = math.pow(10,len)
	out = math.floor(dec*factor)*10+len/factor
// EN = encode_heavy(232,97).print(pos="8") // 232970.02

// @function Decodes encoded float that tracks size of ints in
// decimal of float (slowest)
// @param encoded `float` - the encoded float value
// @returns `[int, int]` - tuple of the 2 ints from encoded float
export method decode_heavy(float encoded) =>
	len = str.length(str.split(str.tostring(encoded),'.').get(1))
	factor = math.pow(10,len)
	decoded = math.floor(encoded/10)/factor
	_a = int(decoded)
	_b = (decoded-_a)*factor
	[_a,_b] 
// [___a,___b]= decode_heavy(EN) // 232,97	
// str.format("\na={0}\nb={1}\n",___a,___b).print(pos="9")



// @function 
//![FrizLabz](https://cdn.discordapp.com/attachments/993257747430772841/1086326365499949076/546666666.gif)    
//---  
//# **Bitwise, Encode, Decode Docs**  
//---  
// - In the documentation you may notice the word decimal   
//   not used as normal this is because when refering to   
//   binary a decimal number is a number that  
//   can be represented with base 10 numbers 0-9   
//   (the wiki below explains better)  
// - A rule of thumb for the two integers being   
//   encoded it to keep both numbers   
//   less than 65535 this is because anything lower uses 16 bits or less   
//   this will maintain 100% accuracy when decoding   
//   although it is possible to do numbers up to 2147483645 with   
//   this library doesnt seem useful enough  
//   to explain or demonstrate.  
// - The functions provided work within this 32-bit range,   
//   where the highest number is all 1s and   
//   the lowest number is all 0s. These functions were created   
//   to overcome the lack of built-in bitwise functions in Pinescript.   
//   By combining two integers into a single number,  
//   the code can access both values i.e when   
//   indexing only one array index  
//   for a matrices row/column, thus improving execution time.   
//   This technique can be applied to various coding   
//   scenarios to enhance performance.  
// - Bitwise functions are a way to use integers in binary form      
//   that can be used to speed up several different processes      
//   most languages have operators to perform these function such as      
//   `<<, >>, &, ^, |, ~` [Wiki](https://en.wikipedia.org/wiki/Bitwise_operation)    
//***       
// ```  
// method bEncode(int n1, int n2) => int
//|   bOr(n1,bShiftLeft(n2,16))
//```     
// Encodes two numbers into one using bit OR. (fastest)      
//### Parameters    
// n1 **`(int)`** - The first number to encode.     
// n2 **`(int)`** - The second number to encode.         
//#### Returns  
// **`int`** - The result of combining the two numbers using bit OR. 
//***       
// ```  
// method bDecode(int n) => int
//|   [n%65536, math.floor(n/65536)]
//```     
// Decodes an integer created by the bCombine function.(fastest)      
//### Parameters    
// n **`(int)`** - The integer to decode.        
//#### Returns  
// **`[int, int]`** - A tuple containing the two decoded components of the integer. 
//***       
// ```  
// method Encode(int a, int b) => float
//```     
//  Encodes by seperating ints into left and right of decimal float     
//### Parameters    
// a **`(int)`** - a int        
// b **`(int)`** - b int        
//#### Returns  
// **`float`** - new float of encoded ints one on left of decimal point one on right 
//***       
// ```  
// method Decode(float encoded) => [int, int]
//```     
// Decodes float of 2 ints seperated by decimal point      
//### Parameters    
// encoded `float` - the encoded float value      
//#### Returns  
// **`[int,int]`** - the 2 ints from encoded float 
//***       
// ```  
// method encode_heavy(int a,int b) => float
//```     
// Encodes by combining numbers and tracking size in the decimal of a floating number (slowest)      
//### Parameters    
// a **`(int)`** - a int   
// b **`(int)`** - b int            
//#### Returns  
// **`float`** - new decimal of encoded ints 
//***       
// ```  
// method decode_heavy(float encoded) => [int, int]
//```     
//  Decodes encoded float that tracks size of ints in decimal of float (slowest)     
//### Parameters    
// encoded `float` - the encoded float value        
//#### Returns  
// **`[int,int]`** - the 2 ints from encoded float 
//***       
//```   
// method bAnd(int a,int b) => int  
//```  
// Returns the bitwise AND of two integers  
//### Parameters    
// **`a (int)`** - The first integer    
// **`b (int)`** - The second integer        
//#### Returns    
// **`int`** The bitwise AND of the two integers  
//*** 
//```   
// method bOr(int a,int b) => int  
//```  
// Performs a bitwise OR operation on two integers.  
//### Parameters    
// **`a (int)`** - The first integer.    
// **`b (int)`** - The second integer.         
//#### Returns     
// **`int`** The result of the bitwise OR operation.  
//***  
//```   
// method bXor(int a,int b) => int  
//```  
// Performs a bitwise Xor operation on two integers.  
//### Parameters    
// **`a (int)`** - The first integer.    
// **`b (int)`** - The second integer.      
//#### Returns     
// **`int`** The result of the bitwise Xor operation.  
//***   
//```  
// method bNot(int n) => int  
//```  
// Performs a bitwise NOT operation on an integer.    
//### Parameters    
// **`n (int)`** - The integer to perform the bitwise NOT operation on.    
//#### Returns    
// **`int`** The result of the bitwise NOT operation.    
//***  
//```  
// method bShiftLeft(int n, int step) => int  
//```  
// Performs a bitwise left shift operation on an integer.    
//### Parameters    
// **`n (int)`** - The integer to perform the bitwise left shift operation on.    
// **`step (int)`** - The number of positions to shift the bits to the left.    
//#### Returns    
// **`int`** The result of the bitwise left shift operation.    
//***  
//```  
// method bShiftRight(int n, int step) => int   
//```  
// Performs a bitwise right shift operation on an integer.    
//### Parameters    
// **`n (int)`** - The integer to perform the bitwise right shift operation on.  
// **`step (int)`** - The number of bits to shift by.    
//#### Returns    
// **`int`** The result of the bitwise right shift operation.    
//***  
//```  
// method bRotateLeft(int n,int step) =>  int    
//```  
// Performs a bitwise right shift operation on an integer.    
//### Parameters    
// **`n (int)`** - The int to perform the bitwise Left rotation on the bits.                          
// **`step (int)`** - The number of bits to shift by.    
//#### Returns    
// **`int`** The result of the bitwise right shift operation.  
//***  
//```  
// method bRotateRight(int n, int step) => int    
//```  
// Performs a bitwise right shift operation on an integer.    
//### Parameters    
// **`n     (int)`** - The int to perform the bitwise Right rotation on the bits.  
// **`step  (int)`** - The number of bits to shift by.    
//#### Returns    
// **`int`** The result of the bitwise right shift operation.    
//***    
//```  
// method bSetCheck(int n, int pos) =>  bool 
//```  
// Checks if the bit at the given position is set to 1.    
//### Parameters    
// **`n (int)`** - The integer to check.  
// **`pos (int)`** - The position of the bit to check.    
//#### Returns    
// **`bool`** True if the bit is set to 1, False otherwise.    
//***  
//```  
// method bClear(int n,int pos) => int   
//```  
// Clears a particular bit of an integer (changes from 1 to 0) passes if bit at pos is 0.    
//### Parameters    
// **`n (int)`** - The integer to clear a bit from.  
// **`pos (int)`** - The zero-based index of the bit to clear.    
//#### Returns    
// **`int`** The result of clearing the specified bit.    
//***  
//```  
// method bFlip0s(int n) => int    
//```  
// Flips all 0 bits in the number to 1.    
//### Parameters    
// **`n (int)`** - The integer to flip the bits of.    
//#### Returns    
// **`int`** The result of flipping all 0 bits in the number.    
//***  
//```  
// method bFlip1s(int n) => int    
//```  
// Flips all 1 bits in the number to 0.    
//### Parameters    
// **`n (int)`** - The integer to flip the bits of.    
//#### Returns    
// **`int`** The result of flipping all 1 bits in the number.    
//***  
//```  
// method bFlipAll(int n) => int    
//```  
// Flips all bits in the number.    
//### Parameters    
// **`n (int)`** - The integer to flip the bits of.    
//#### Returns    
// **`int`** The result of flipping all bits in the number.    
//***    
//```  
// method bSet(int n,int pos,int newBit=na) => int  
//```  
// Changes the value of the bit at the given position.    
//### Parameters    
// **`n (int)`** - The integer to modify.  
// **`pos (int)`** - The position of the bit to change.  
// **`newBit (int)`** - na = flips bit at pos | The new value of the bit (0 or 1).  
//#### Returns  
// **`int`** The modified integer.    
//***  
//```  
// method changeDigit(int n,int pos,int newDigit) => int    
//```  
// Changes the value of the digit at the given position.    
//### Parameters    
// **`n (int)`** - The integer to modify.  
// **`pos (int)`** - The position of the digit to change.  
// **`newDigit (int)`** - The new value of the digit (0-9).  
//#### Returns  
// **`int`** The modified integer.    
//***   
//```  
// method bSwap(int n, int i, int j) => int   
//```  
// Switch the position of 2 bits of an `int`    
//### Parameters    
// **`n (int)`** - int to manipulate  
// **`i (int)`** - bit pos to switch with `j`  
// **`j (int)`** - bit pos to switch with `i`  
//#### Returns  
// **`int`** new int with bits switched     
//***  
//```  
// method bPalindrome(int n) => bool  
//```  
// Checks to see if the binary form is a `Palindrome`   
// (reads the same left to right and vice versa)    
//### Parameters    
// **`n (int)`** - int to check  
//#### Returns  
// **`bool`** result of check     
//***  
//```  
// method bEven(int n) => bool   
//```  
// Checks if n is `Even`    
//### Parameters    
// **`n (int)`** - The integer to check.  
//#### Returns  
// **`bool`** result.    
//*** 
//```  
// method bOdd(int n) =>  bool    
//```  
// Checks if n is `Even` if not even `Odd`    
//### Parameters    
// **`n (int)`** - The integer to check.  
//#### Returns  
// **`bool`** result.    
//***  
//```  
// method bPowerOfTwo(int n) => bool    
//```  
// Checks if n is a Power of 2.    
//### Parameters    
// **`n (int)`** - number to check.  
//#### Returns  
// **`bool`** result.    
//***  
//```  
// method bCount(int n,string to_count="all") => int    
//```  
// Counts the number of bits that are equal to 1 in an integer.    
//### Parameters    
// **`n (int)`** - The integer to count the bits in.  
//#### Returns  
// **`int`** The number of bits that are equal to 1 in `n`.    
//***  
//```  
// method GCD(int a, int b) => int  
//```  
// Finds the greatest common divisor (GCD) of two numbers.  
//### Parameters    
// **`a (int)`** - The first number.      
// **`b (int)`** - The second number.         
//#### Returns    
// **`int`** The GCD of `a` and `b`.  
//***  
//```   
// method LCM(int a, int b) => int  
//```  
// Finds the least common multiple (LCM) of two integers.  
//### Parameters    
// **`a (int)`** - The first integer.      
// **`b (int)`** - The second integer.         
//#### Returns    
// **`int`** The LCM of `a` and `b`.    
//***  
//```   
// method aLCM(int a, int b) => int   
//```  
// Finds the least common multiple (LCM) of a list of integers.  
//### Parameters    
// **`nums (int[])`** - The list of integers.        
//#### Returns    
// **`int`** The LCM of the integers in `nums`.  
//*** 
//```
// method adjustedLCM(array<int> nums,int LCM) =>
//```
// Adjust array of integers to Least Common Multiple (LCM)
//### Parameters  
// **`nums (int[])`** - The first integer  
// **`LCM  (int)`** - The second integer   
//#### Returns
// **`int[]`** - array of ints with LCM
//***
//```  
// method charAt(string str, int pos) => string    
//```  
// Gets the char at the given position (index left to right).    
//### Parameters    
// **`str (string)`** - string to pull char from.  
// **`pos (int)`** - pos to get char from string.  
//#### Returns  
// **`string`** char from pos of string or "" if pos is not within index range    
//***  
//```  
// method decimalToBinary(int num) => string    
//```  
// Converts a decimal number to binary    
//### Parameters    
// **`num (int)`** - The decimal number to convert to binary  
//#### Returns  
// **`string`** The binary representation of the decimal number    
//***  
//```  
// method binaryToDecimal(string binary) => int    
//```  
// Converts a binary number to decimal number 
//### Parameters    
// **`binary (string)`** - The binary number to convert to decimal  
//#### Returns  
// **`int`** The decimal representation of the binary number    
//***  
//```  
// method float_decimal_len(float n) => int    
//```  
// Way of finding float decimal length using arithmetic     
//### Parameters    
// **`x (float)`** value to find number of decimal places  
//#### Returns  
// **`int`** number of decimal places     
//***  
//```  
// method int_len(int n) => int    
//```  
// Way of finding number length using arithmetic     
//### Parameters    
// **`n (int)`** value to find length of number  
//#### Returns  
// **`int`** lenth of nunber i.e. 23 == 2    
//***  
//```  
// method float_decimal_to_whole(float s) => int    
//```  
// Converts a float decimal number to a whole integer number  
// by removing the decimal point and leading zeroes. `0.22 to 2` 
//### Parameters    
// **`s (string)`** - The decimal number represented as a string.  
//#### Returns  
// **`int`** - The integer obtained by removing the decimal point and leading zeroes from `s`.    
//***  
//```  
// method fractional_part(float x) => float    
//```  
// Returns the fractional part of a float.    
//### Parameters    
// **`x (float)`** - The float to get the fractional part of.  
//#### Returns  
// **`float`** The fractional part of the float.    
//***  
//```  
// method form_decimal(int a,int b,bool zero_fix=false) => [float , int]  
//```  
// Helper to form 2 ints into 1 float seperated by the decimal    
//### Parameters    
// **`a (float)`** - a int  
// **`b (float)`** - b int  
// **`zero_fix (bool)`** - fix for trailing zeros being truncated when converting to float  
//#### Returns  
// **`[decimal,convert]`**  
// decimal = decimal of ints  
// convert = string version of last for future use to ref length      
//***  
export docs() => 
    ''


