For a project I need to implement a method that adds parts of the value or the whole value to the end of the value.
For example I have my int 11 and want to add 3 digits to 11 from the same int like: 11111.
Second example 10 with 6 more digits: 10101010
So I always need to add the value I have at the end a certain amount of times.
Thought about making an array and entering the numbers but the result needs to be an int to.
I am not able to find a mathematical way at the moment which is smooth? Any ideas to help me out?
There is no good 'mathematical' way, because you must operate on a numeral, not a number. A numeral is the string representation of a number in a specific radix. That means you can solve the problem best using string operators.
First convert the number to a string. Then repeat the string until it has at least the required length. Next, take the substring of the exact required length. Finally, parse the numeral back to an int (or BigInteger).
Stephan van Hulst: So I basically transform my Int to a String and repeat the String according to the number of times required?
Do I need to put each digit of the Int to a String so I can also cut the value into two parts if I need to split up due to the digit limit?
So bascially I use my value and transform it in a String and afterward put it in a char array.
So now my numbers are contained in the char array, correct?
I can simply Loop through the array according to the number of digits I can use and add them to a String.
Afterwards we transform the String back to an int?
The input of the variables are not normal ints they are written in binary Code for example: 0b011.
Now when I transform the Input to a String and work with my char array it only work with the value 3 not 0b011.
Is there an easy way how I can add the missing parts to the binary Code?
Tried to transform the int to binary with: Integer.toBinary but then I am loosing the first part and the 0 before the 11.
Then it looks like your code is converting data to numeric values at some point. But you don't want to do that, it's all supposed to be character manipulation (as far as I can tell). So clear out the code which converts to numeric values.
I unfortunately I can't clear out the code that transforms it into numeric values.
Is there a way to access the Input data directly before it gets transformed?
Otherwise I have no idea how I can repeat the Binary Code under the consideration that it might include 011011 (0) that I cannot see when i transform the int to Binary...