This question already has answers here:
How do you convert a byte array to a hexadecimal string, and vice versa?
(53 answers)
Closed 4 years ago.
I am looking for a way or multiple ways (Always good to know many ways) how to convert Text (String) to HexaDecimal like this http://codebeautify.org/string-hex-converter
Any help would be appreciated.
I've been looking for hours around different places and I have so far found no code that could potentionally do this for me.
All the ways that this could be done is accepted, I love learning about coding.
String to Hex:
Integer.decode(hexString);
Hex to String:
Integer.toHexString(integer);
Related
This question already has answers here:
How to convert byte[] to Byte[] and the other way around?
(9 answers)
Closed 3 years ago.
I want to convert a Byte array into a byte array, but I don't see any way to do so in java without using a loop.
Can someone please tell me a way to make it ?
There is no need for that, because Java has an auto-unboxing system that automatically converts Bytes to bytes. So, you can use them the same way. But if you really have to, you have to use a loop.
This question already has answers here:
Format double value in scientific notation
(4 answers)
Closed 6 years ago.
I want to show factorial of a number in scientific notation.
For example - 100! = "9.332621544e+157"
Is there any other way to do this besides NumberFormat? This is my code so far -
BigDecimal res=new BigDecimal("1");
for(int i=2;i<=x;i++){
res=res.multiply(BigDecimal.valueOf(i));
}
str=String.valueOf(res+"");
display.setText(str);
I'm really sorry if this question is vague to understand. Any help would be appreciated. Thanks in advance.
Not nice but changing
str=String.valueOf(res+"");
to
String str=res.doubleValue()+"";
will do the job
Using NumberFormat is the way to go but if you don't want to use that you could use a PrintStream
See Formatting Numeric Print Output for more info
This question already has answers here:
Subscript and Superscript a String in Android
(15 answers)
Closed 8 years ago.
I am writing a simple android app and I would like to set the text of a button to be X^n but I want it to look the same way as it would if you would write it on a piece of paper( for example 2⁶).
I know there are several unicode characters that does it for a small group of numbers but I am looking for a generel function (or any other way) that takes two integers and output the first by the power of the second. For example:
int X=2;
int n=6;
function(X , n) ==> 2⁶
I know a similar question was asked here before but its answers were not sufficient because I want to use variables' values and not actual numbers;
Thanks!
You can use html's <sup> tags for that:
button.setText(Html.fromHtml("X<sup>n</sup>"));
This question already has answers here:
How do I compare strings in Java?
(23 answers)
Closed 8 years ago.
I'm trying to do a comparison in Java with 2 strings containing a extended ASCII character.
boolean result = "éasdfasdf".substring(0,1).equals("é");
Can somebody explain why this results false? I think it has something to do with character encoding, but I can't figure out what exactly the problem is here...
Update: ideone.com does successfully run these 2 lines, so the problem is locally in my box. I think I found some more proof of that:
System.out.println("éb".charAt(1) == 'b');
Does also fails... Can it be the problem of 2 different character encodings?
Use
boolean result = "éasdfasdf".substring(0,1).equals("é")
And it will give expected result!The reason is simple - using '==' you compare objects by reference, not by value. So equals() solves this problem
This question already has answers here:
Guessing the encoding of text represented as byte[] in Java
(7 answers)
Closed 8 years ago.
I'm receiving a byte[] of information in an unspecified encoding format. Is there a way to convert it to a String without knowing the character encoding?
The tool of choice is CharsetMatch from ICU: http://userguide.icu-project.org/conversion/detection
It is not an exact science, so there is a confidence score that you have to watch and it will take some experimentation, but will definitely get you where you want to go. Good Luck!