binary « Number « Java Data Type Q&A





1. counting number of ones in binary representation of a number    stackoverflow.com

Possible Duplicate:
Best algorithm to count the number of set bits in a 32-bit integer?
I want to find out how many 1s are there in ...

2. working with binary numbers in java    stackoverflow.com

I would like to know which one is the best way to work with binary numbers in java. I need a way to create an array of binary numbers and do some ...

3. How to derive Binary representation of Negative Numbers    coderanch.com

Hi, Vineet. A little rule that I use when I need to represent negative numbers in binary is ~i = -i-1. That is, the bitwise inversion of "i" is equivalent to negative "i" less one. In your example, you're looking for the binary representation of -192. Since -192 = -191-1, the following statement is true: ~191 = -192. So if we ...

4. binary numbers / shifting    coderanch.com

5. outputting a number in binary form    coderanch.com

Thanks for the suggestions...I have tried both ways ans they work great. I am actually going to resort to creating my own method for displaying the binary format for a number. I am head up a study group at work for Java Certification and I have come up with a 'homework' assignment for the engineers to do to get more familiar ...

6. what is Binary number    coderanch.com

Exactly! When you think about binary representations of numbers, all you have is ones and zeroes: 0 = 0 1 = 1 10 = 2 11 = 3 100 = 4 101 = 5 and so on. It seems a little complicated at first, but do some reading and you will start to understand and appreciate computers a lot more! ------------------ ...

7. Need remedial help with binary numbers    coderanch.com

Can anyone direct me to some good sources on the Web dealing with the basics of binary numbers and how they work? I read the article in the Campfire about bit manipulation in Java and it was tremendously helpful, but I'm missing some basic things like why the heck *is* -1 represented as 11111111 in binary? Something along the lines of ...

8. negative number in binary    coderanch.com

Hi, can anybody help? Thanks in advance. what i know is to get the binary format of positive numbers, like 25: 25 = 1 + 8 + 16, that is 0000 0001 ///this is one 0000 1000 //this is eight 0001 0000 //this is sixteen --------- 0001 1001 //this is what i want: twenty five in byte type 00000000 00000000 00000000 ...

9. Manipulating Binary Numbers    coderanch.com

Hi All, I wonder does anybody know where i can get a class for manipulating binary numbers? I'd write it myself, but my assignment is due in 6 days & i don't really have time! Plus, it would break the rule about not re-inventing the wheel. And i'm a very good girl - i don't want to break rules!!! Thanks a ...





10. Outputing Binary Numbers    coderanch.com

I am trying to output binary numbers to the standard stream. The problem is that I want to display them in the mathematically correct format. Using 7.5 as a decimal example, to display it as: 111.1 Do I have to write my own method to convert these, or is there a simpler way? Thanks, Joe Hoppe

11. Literal for binary number    coderanch.com

12. Binary Numbers Comparison.    coderanch.com

You don't have to convert to decimals. Every bit is 2^x so you at least need to find the bits that are 1 and calculate what x is for that bit. Without converting to decimal I think the faster way to get the most significant bit that is 1 of each number and compare that. Oh you do need to watch ...

13. Sum binary numbers    java-forums.org

Hello: I wrote the following code to sum two binary numbers of the same length: Java Code: public class BinarySum { public static void main(String[] args) { int[] a = {0,1,1,1,1,1}; int[] b = {0,1,1,0,1,1}; int[] c = new int[a.length + 1]; int n = a.length + 1; int m = a.length; int aux = 0; int i; for(i=1 ; i ...

14. All possible combinations given a binary number    java-forums.org

Hi all, I have a 2D array which represents the binary numbers. Given a 2D array of [count][posvalues], count refers to the number of binary, and posvalues refer to the possible values of each binary. Ex. binary num: [0, 1] [0,1] [0,1] Count = 3 Possible Values = 2 (given by 0 and 1) I want to find all the possible ...

15. Reads a number and prints it's binary digits, need help :)    java-forums.org

Java Code: import java.util.Scanner; //Class definition public class Bits { public static void main(String[] args) { // declare int n; int rem; // User input Scanner in = new Scanner(System.in); System.out.println(); n = in.nextInt(); // Calculate while (n > 0) { System.out.print(rem = n % 2); n = n / 2; } } } That's what I have so far, but ...

16. Code to convert binary number to base 10 number    java-forums.org

Hello, I'd like help converting a binary number to a base 10 number using a loop statement. I've tried to no success to do it myself. Here is the problem in its entirety, though I'm having trouble with that one specific part. Write a Java project (Applet) with two classes. In the init() method of the driver class, use a sentinel ...





17. converting number to binary    forums.oracle.com

im experimenting using for loops converting number to binary and vice versa binary to number i cant get it im only new to programming im a student of computer science im only a freshmen and i really want to learn java programming. Presentl im practicing looping concepts can anybody help me thanks. and Im thinking to use arrays. thanks

18. expressing a negative number in binary    forums.oracle.com

20. Is this code terribly written to work out a binary number    forums.oracle.com

Thanks mel for the really informative response The i really was pointless but i did have a valid reason for this, i promise! I was going to use a normal array and then use the i to add the element to the i'th position. However the rush i was in lead for me to ditch the array and opt for an ...

21. next binary number    forums.oracle.com

22. Validating binary numbers    forums.oracle.com

Oops sorry it is named validBinairies not count1's, i was looking at the wrong method. It is a string type, but not sure if i need to convert it to an int to count the 1's. So i do need help naming the return method and to figure out how to check if its valid.

23. generating binary numbers    forums.oracle.com

I'm assuming the objective is to add 1 to the given binary string, since it's rather unclear. And I'm assuming this is for a class assignment, because it's utterly pointless to do it this way instead of just working with numbers and converting to base 2 when you want to print. "numOnes" is pointless. You don't use it. If the goal ...

24. help with converting binary numbers    forums.oracle.com

I would use the 'and' & and bitshift << operators instead of all that math, it would make it much more readable and easier to understand. You could also cheat and just do binum = Integer.parseInt(binum_st,2); Even doing it with the division and modulo, it might be easier to loop i from 0 to the string length on each character in ...