This question already has answers here:
Converting an int to a binary string representation in Java?
(19 answers)
Closed 9 years ago.
how can I get the binary value of a character
Ex: Letter C (ASCII Code= 067) To Binary value 01000011.
Use Integer.toBinaryString(character...);
Related
This question already has answers here:
How to convert an Int to a String of a given length with leading zeros to align?
(8 answers)
How can I pad a String in Java?
(32 answers)
Closed 6 years ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Duplicate This question has been answered, is not unique, and doesn’t differentiate itself from another question.
I have a number, I want to pad this number with zero's in the beginning if the digits are less that 9 digits.
currently if I have a number lets say:
val num = "123"
if I use padTo(9,"0") I will get "123000000" but I want "000000123"...
what is the best solution for this?
would be better to get the solution in scala
thanks
This question already has answers here:
Java String.split() sometimes giving blank strings
(3 answers)
Why in Java 8 split sometimes removes empty strings at start of result array?
(3 answers)
Closed 8 years ago.
I have a string like "2020". When I split it with split(""). Then i checked its length. It is giving me 5 . But it should give 4. What is the reason
This question already has answers here:
Print an integer in binary format in Java
(24 answers)
Closed 8 years ago.
Say I have an integer number: 11728322732
how can i convert it to a string according to its byte representation, i.e 11100011000000001100000111110001 (32 bits \ 4 bytes \ integer)
Thanks
Here it is:
Long.toBinaryString(11728322732L);
Actually, 11728322732 is not an Integer but a Long (because it is greater than Integer.MAX_VALUE). So if you really want to convert this long to a 32-bits int (can't figure why actually), you could do:
Integer.toBinaryString((int)11728322732L);
This question already has answers here:
Gets last digit of a number
(12 answers)
Closed 8 years ago.
I am trying to write Java code to obtain the last digit of a long (i.e. the rightmost digit).
If I were trying to obtain the last element of a string, I would use the substring() method.
What is the alternative or equivalent way when getting the last digit of a long?
You can do
long digit = Math.abs(number%10);
This question already has answers here:
Java code To convert byte to Hexadecimal
(23 answers)
Closed 9 years ago.
I have a MAC address represented as a byte[] in Java and want it as a hexadecimal string, as they are usually represented. How can I do this with as easy as possible?
The byte array has length 6.
Try this:
String hexValue = String.format("%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);