I have a number and I want to print it in binary. I don't want to do it by writing an algorithm, Is there any built-in function for that in Java?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Here no need to depend only on binary or any other format... one flexible built in function is available That prints whichever format you want in your program.. Integer.toString(int,representation);
This is the simplest way of printing the internal binary representation of an integer. For Example: If we take n as 17 then the output will be: 0000 0000 0000 0000 0000 0000 0001 0001
I needed something to print things out nicely and separate the bits every n-bit. In other words display the leading zeros and show something like this:
So here's what I wrote:
Invoke it like this:
Try this way:
}
10010100
Output: