I have a project where I need to add binary numbers using C language. I don't know where to start. Help?
I have a project where I need to add binary numbers using C language. I don't know where to start. Help?
Do you mean you have strings of 1s and 0s that you need to add as if they were binary numbers?
All actual integers are held in binary (on the whole) anyway so adding 2 binary digits is as simple as
int a = 2; // binary 10
int b = 7; // binary 111
int c;
c = a + b; // result = 9, binary 1001
Yes I'm going to add strings of 1 and 0 as if they're binary numbers. The program that I need is this, the first binary number will be asked. If the user typed a number greater than 1, an error message will come out and it will ask to give a binary number again. After that another binary number will be asked and then it will display the result in binary numbers also. I don't know how many variables to declare. I really don't know where to start
Start by asking for the binary number. Then check the number for illegal characters.
I get that part and what I will do if a wrong number is entered. What I don't know is how many variables I should declare or what commands I should use. I also don't know that addition part. :(
I get that part and what I will do if a wrong number is entered.
A contraire. As the rules state, "Do provide evidence of having done some work yourself if posting questions from schoolwork assignments". I see no evidence.
What I don't know is how many variables I should declare or what commands I should use.
This completely depends on what algorithm you decide to implement.
Sit at your desk with pen and paper. Write down two binary numbers. Add them. Now think about what you just did and write down each step you performed in excruciating detail.
There is your algorithm. Convert it to code.
One little question bit off-toppic. I get an array of chars ended with a binary zero. I need to count how many chars do I have in the array. Can I check the ending like this?
while(s[i]!=0) { length++; i++}
I'm a bit confused about what a binary zero is. Do I get it right that it is equal to a regular zero? :)
EDIT: And how can I add the binary zero to the end of my own array? :D
One little question bit off-toppic. I get an array of chars ended with a binary zero. I need to count how many chars do I have in the array. Can I check the ending like this?
while(s[i]!=0) { length++; i++}
I'm a bit confused about what a binary zero is. Do I get it right that it is equal to a regular zero? :)
EDIT: And how can I add the binary zero to the end of my own array? :D
Please start new thread for new question....
>>And how can I add the binary zero to the end of my own array?
I think you are talking about '\0' . A char string is always terminated by '\0' char.
Thank you this is exactly the thing I've been looking for.