Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Liquid Web Managed Dedicated Server: RAID 1 SSD with 16GB of RAM minimum! 24/7 On-Site Heroic Support! Industry-Leading SLA!

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Liquid Web Cloud VPS Hosting

8,365 questions

11,625 answers

573 users

How to convert a negative integer into binary string with Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {
  
    public static void main(String[] args) {
         
        for (int i = -15; i <= 0; i++) 
              System.out.println(i + ": " + Integer.toBinaryString(i));
    }
}
    
/*
run:
   
-15: 11111111111111111111111111110001
-14: 11111111111111111111111111110010
-13: 11111111111111111111111111110011
-12: 11111111111111111111111111110100
-11: 11111111111111111111111111110101
-10: 11111111111111111111111111110110
-9: 11111111111111111111111111110111
-8: 11111111111111111111111111111000
-7: 11111111111111111111111111111001
-6: 11111111111111111111111111111010
-5: 11111111111111111111111111111011
-4: 11111111111111111111111111111100
-3: 11111111111111111111111111111101
-2: 11111111111111111111111111111110
-1: 11111111111111111111111111111111
0: 0
    
*/

 




answered Jun 28, 2017 by avibootz
...