Robin Robin - 23 days ago 6
Java Question

How to extend a char array in java

I have a function that convert numbers to binary representation such as each bit is a char with a value 0 or 1, for example:
1=0001
f=1111

but I need to make all numbers represented as 13 bit i.e. :

0001=0000000000001

for(int i=0;i<8192;i++){
char[]indexIn=String.valueOf(i).toCharArray();
char[]indexOut=c.convertHexToBinary(indexIn);
}


I need to extend indexOut while it is variable in length because the number of bits needed to represent 1 not as 25.

Answer

try this,

import java.util.*;
public class fib{
    public static void main(String[] args){
        int num = 0001;
        String formatted = String.format("%013d", num);
        System.out.println(formatted);
    }
}