My homework is to create a program to scan in and add binary numbers and print them like so
Enter a binary number: 1
sum = 1 decimal 1 hex and 00000001 binary
Enter a binary number: 10
sum = 3 decimal 3 hex and 00000011 binary
etc.
I know that bit manipulation and input and output of strings is necessary to create this program, but I'm not experienced with either. The code I have compiles, but I am unable to make it do anything useful, and most of it is wrong. My do loop is probably wrong and I don't understand how to properly use bit manipulation. I'm rather clueless, can anyone give me some ideas on what to do next?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "stdafx.h"
#include "stdio.h"
#include "math.h"
#include "iostream"
#include "string"
using namespace std;
int sum = 0;
int i = 0;
int c = 0;
int Q;
string binaryInput;
int main()
{
cout << ("Enter a binary number: "); //Prompts the user for input
cin >> binaryInput; //Writes the binary input to cin
do { //do loop to read the binary one digit at a time
i++;
cout << binaryInput[i]; //I don't understand how to output a specific digit of the string and manipulate it
c = binaryInput[i];
if (c = Q)
break;
else;
sum = sum + c * 2 * i; // supposed to be sum = sum + binaryInput[i] * pow(2,i), this is where the binary is converted to decimal
printf("nsum = %*d ", 3, sum);
printf("decimal %*x " , 2, sum);
printf("hex %08d binary", sum);
} while (i
check if string contain only a-z/A-Z
Is where any way to check if string contains only a-z/A-Z, without writing an array with all possible letters and then looping it.Code: $available = array('a', 'b', 'c, 'd'); //write a-zfor
Just cannot get 'area' to submit to db using same php code as already used
Basically all i have done is just modified some code and added an area section.The form is allready submitting other things like location price etc.And i have simply added a field in db called area
Quick fix: Conditional statement with an array
Hi, I'm getting the temperature value off of the Environment Canada website along with the icon filename, so I can display my own icons and temperature on my site. All this works and I can display the
Inter Company -- Resources Related Billing (Services Industry)
Hello,
Undefined Index Notice In Internet Explorer Only
I am getting the following notice: QuoteNotice: Undefined index: jrox in /home/ycsn/public_html/mem/includes/html/templates/template_member_home_page.php on line 20It only appears within Internet
PHP Multiples of 2, Show posts...not working (wordpress)
I have been using this code to show div.example with 6 li columns inside it, each li is a post with its info inside.Once it gets to the 6th li it closes the div.example and starts a new one. This to
Passing PHP variables from one page to another
Hello-I'm having trouble figuring out how to transport a variable from one php file to another. Specifically, the name of an image, to be used as a subject in a form mail. I don't even really have the
Wierd echo error?
Hi, i got the most wierd php error ever and i don't know why..Code: echo "<td><strong>MP:</strong></td>"; echo
Redistributing dependent dlls
Hai all ,I have created an application in VC++ using VS2008 in a development machine which runs on Vista, now i need to run that application in a target machine which runs on windows XP SP2 which does
Alternate messaging
I have 4 strings in MySQL db1$string1 : Hello$string2 : Hi$string3 : Great$string4 : ThanksAnd I have 3 accounts MySQL db2$User1 : $Pw1$User2 : $Pw2$User3 : $Pw3expected result---------------Hello