Languages
[Edit]
EN

Java - convert long to binary String with leading zeros

11 points
Created by:
Root-ssh
178260

Short solution:

In java simples way to convert long to binary String with leading zeros is to use Long.toBinaryString(number) and String.format() method. 
Note that as first param in String format we pass number of leading spaces and we replace all spaces with 0. Usually we use 32 or 64 padding zeros.

1. Convert long to binary String with leading zeros

Edit

Output:

2. Convert large long to binary String - 64 length padding

Edit

Output:

3. Print long to binary - between 0 and 8 with leading zeros

Edit

Output:

Merged questions

Edit
  1. Java - convert long to binary String representation with leading zeros
  2. How to cast long to binary string with padding to 64 digits in java?
  3. Java - print long in binary format with leading zeros
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Java conversion

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join