How does Base32 encoding work in Java? [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have this code to generate a random key.
new BigInteger(130, random).toString(32);
From what I understand, the first part of the code will create a 130 bit, random, integer. Then, the .toString(int radix) method will be called on it and the number will be converted to an alpha-numeric string.
What I can't understand is which alphabet is used for the characters; in other words, which key is mapped to which character?
Note: I looked for how a Base 32 conversion can happen, but I couldn't come up with anything useful since it doesn't seem to be a unique method to do that.

The javadoc says:
" The digit-to-character mapping provided by Character.forDigit is used, and a minus sign is prepended if appropriate.".
And the latter javadoc says:
" If the digit is less than 10, then '0' + digit is returned. Otherwise, the value 'a' + digit - 10 is returned."

Related

How to display a portion of a string at an index of a string array [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a string array
String[] albumnames;
now how to take a string from particular index position with limited number of charachters.
For example,
if, albumnames[position] have value "abcdefghijk"
then i want to take the first 5 characters only.
That is "abcde".
The substring method of String can be used to achieve this. Try
String s = albumnames[position].substring(0,5);
See substring docs
albumnames[position].substring(0,5);
you can see the methods in String class, like substring, indexof

parse string containing number with minus on the right [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a problem - is there any possibility to recognize in the text the negative number, that has a minus sign on the right?
E.g. I'm thinking about number like that: 1500.0- (instead of -1500.0).
Thank you in advance for any help.
Not only is it possible, it is actually easier to handle a trailing sign. You just convert the number as usual, continuing while you keep getting digits, then if it ends with a minus sign just negate it. Easier than having to remember a leading sign.
Despite the names of the methods provided in the JDK, this is not 'parsing', it is radix conversion.
You could use charAt or a regular Expression, and many more...
String s = "1500.00-";
if (s.charAt(s.length()-2) == '-'){
//minus on the right.
}
First move the minus (if any) from the end to the start:
num = num.replaceAll("(.*)(-)?$", "$2$1");
The good thing here is that if there's no minus sign at the end, or yjr minus us alteady at the start, nothing change it made.
Then parse it as normal, eg:
double d = Double.parseDouble(num);

multiply large no. in array [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
multiply any 2 numbers. The numbers can be extremely large (i.e. run into hundreds of digits) and are provided as strings.
The expected output is a string which represents the product of the two numbers.
example-
multiply("268435456","524288")="140737488355328"
multiply("12321412423524534534543","0")="0"
Use BigDecimal, which has a multiply method and a constructor which takes a String. It also contains corresponding toString() and toPlainString() methods to get your result as a string.
(If the numbers are always whole numbers, then use BigInteger instead.)

How do I split a String in Java up to a certain point, keeping everything after that point as a separate string? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What I am looking to do is split a given string in Java using a tab delimiter. After the seventh split, I would like to keep everything after that point as an eighth split. This last split will contain tabs also, but must remain intact.
Use the split method that takes two parameters, the second being the split limit. You can pass in a limit of 8. The eighth element will contain the rest of the string after the seventh split.

How to create random cell number for testing purpose [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have to create a random cellnumber 07939393914 for automation testing purpose.
Last 079393(5 digits) digits should change randamly.. each time test runs..
Can any one suggest JAVA code for this ? or else Selenium Java code ?
Thanks
Is this a number or a String? I ask as it has a leading zero.
Take you initial number as 7939300000
then add to it Math.round(Math.Random()*10000)
If you want it as a String, take your string as "079393" and use Integer.toString on the result above, then concatentate them
Use RandomStringUtils class.
String randomNumbers = RandomStringUtils.randomNumeric(5);
String phNo = 079393+randomNumbers;
var num=Math.ceil(Math.Random()*100000)
for random first 5 digit numbers
and add
var your_last_5digits; //as string to your last 5 digits
cellNumber='0'+num+your_last_5digits;

Categories