Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
please help me...
im trying to write a program that accepts 2 16-bit binary in 0's and 1's and adds the two no's and displays the result in binary.
2. wants to convert the two binary no's and the result into corresponding decimal no.example: 0110000000000000
0110000000000000
------------------
11000000000000002. 24576
+ 24576
--------
-16384im thinking the logic is correct and im not getting any errors but not adding and converting....kindly help me
Thank u
Nirav
#include
#include
#include
#includevoid bin_add(char *, char *);
void char_2_dec(char *);int main()
{
char num1[17], num2[17];
int i;
cout = 0; k--)
{
if(val1[k] != val2[k])
{
if(carry == 0)
result[k] = 1;
else
result[k] = 0;
}
else if((val1[k] == 0) && (val2[k] == 0))
{
if(carry == 0)
result[k] = 0;
else
result[k] = 1;cout << " result: " << result[k] << endl;
}
else
{
if(carry == 0)
{
result[k] = 0;
carry = 1;
}
else
{
result[k] = 1;
carry = 1;
}
}
}
cout << " The Result is: " << result << endl;
}void char_2_dec(char *val)
{
char dec [17];strcpy(dec,val);
int max_index = 15, exp;
double sum = 0;for(int k = 0; k <= max_index; k++)
{
exp = max_index - k;
cout << " exp is " << endl;
cout << " power is : " << pow(2,exp);
cout << " value " << dec[k] << endl;if(dec[k] == 1)
sum = sum + pow(2,exp);
cout << " sum: " << sum << endl;
}cout << " The Decimal value of " << dec << " is " << sum << endl;
}

Hi Nirav,
Your logic seems to be OK and it should work. In your post there are few lines missing. Check your posted message. If you can send the whole code without any missing lines then I can tell you exactly why its not working. You can email me the code if you prefer doing so or see that the code is correctly displayed in your next post.Sajid Mohammed ( sajleo@yahoo.com )

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |