Not Yet Answered # Adding binary numbers in C language

Banfa 597 Discussion Starter harunosakura Discussion Starter harunosakura WaltP 2,905 Lerilaine vinitmittal2008 37 Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

0

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
```

0

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

0

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. :(

0

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.

0

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

*Edited 6 Years Ago by Lerilaine*: n/a

0

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.

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...