Visual C++ :: Converting Decimal Number Given By User To Binary?

Dec 19, 2014

Write a C++ program that adds three binary numbers of 8-bit each. Every number is stored into an array of 8 elements.

Example:

Array A
0 1 2 3 4 5 6 7
0 1 1 0 1 1 1 0
+
Array B
0 1 2 3 4 5 6 7
0 1 1 0 1 1 1 0
+
Array C
0 1 2 3 4 5 6 7
0 1 1 0 1 1 1 0

Store the result into an array D of 8 elements. Your program should show the decimal numbers for every binary number. Print screen of 6 answers. This means you should try your program six times with different numbers in every run and show the printed screen result.

View 5 Replies


ADVERTISEMENT

C++ :: Converting Decimal To Binary Using Recursion

Feb 25, 2013

I'm trying to write a program that converts a decimal number to a binary one. I have most of the program written, but I am having a little bit of trouble. Whenever I enter a decimal number, the program will convert it correctly to binary, however, the last number is not included in the conversion. EX: Converting 37 into binary (0100101) yields 010010 when entered into the program. BTW the program must utilize recursion to achieve this goal.

#include <iostream>
using namespace std;
void decToBinary(int num1);
int main() {
int num1;

[code]....

View 4 Replies View Related

C++ :: Converting Binary Numbers Into Decimal

Apr 25, 2014

This is the question: [URL] .....

Now I have the binary numbers printed out in my code, but I don't know how I can covert them into to decimal.

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main() {
int numberOfDigits;
int numberOfRows;
char flag;

[Code] ....

View 1 Replies View Related

C :: Converting Decimal Number To Any Base Then Find Ones And Twos Complement

Oct 10, 2014

I have the code working on converting a decimal number to base 1 through 16. I need getting the code to output the one's and two's complement.

Code:
#include <stdio.h>
int main(void) {
char base_digits[16] =
{'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

int converted_number[64];
long int number_to_convert;
int next_digit, base, index=0, a;

/* get the number and base */

[Code] ....

View 8 Replies View Related

C++ :: Convert 8-digit Binary Number To Decimal Number?

Jul 6, 2013

Code: Complete the program below which converts a binary number into a decimal number. Sample outputs are shown belowComplete the program below which converts a binary number into a decimal number. Sample outputs are shown below.

Sample Output 1:

8-bit Binary Number => 11111111
Decimal Number = 255

Sample Output 2:

8-bit Binary Number => 10101010
Decimal Number = 170

Sample Output 3:

8-bit Binary Number => 101010102
Number entered is not a binary number

#include <iostream>
using namespace std;
int main()
{
int num;

[code]....

View 2 Replies View Related

C :: Binary Number To Decimal

Mar 30, 2014

I am very new to programming and have been working on a program that can receive decimals or binary numbers and convert them. The decimal --> binary works fine. For some reason I cannot figure out I cannot get the "BinaryToDecimal" function to perform. By putting a "printf" into the for-loop.

Code:

#include <stdio.h>#include <string.h>
#include <math.h>
char* ReverseString (char _result[]) {
int start, end, length = strlen(_result);
char swap;
for (start = 0, end = length-1; start < end; start++, end--)

[code]....

View 2 Replies View Related

C/C++ :: Binary Number Into Decimal?

Sep 10, 2014

I have a code and am asked to modify it so that it will take as input as unsigned binary number up to 16 digits in length and convert it into its equivalent decimal number and output that decimal number.

All I know is that I use library function strlen() in <cstring> to calculate the length of the input string.

I also know I have to use something called pow(2,4);

//pow (); is found in cmath

I was told to use sum = sum >>16-l; (l is the length of />/>

#include <iostream>
using namespace std;
int main() {

[Code]....

View 4 Replies View Related

C++ :: User To Enter Decimal Value Then Display Its Corresponding Binary Numbers

Sep 13, 2013

Create a program that will ask the user to enter a decimal value (1-999999) then display its corresponding binary numbers. Repeat this process until the value entered is equal to 0. Use the following Function Prototype:

void BinCodes(int value);
Sample Input/Output:
Enter a Decimal: 35
Binary: 100011
Enter a Decimal: 184
Binary: 10111000
Enter a Decimal: 0

View 4 Replies View Related

C++ :: Convert Binary Number Into A Decimal Number

Jul 5, 2013

Here's the part of the codes where I tried to use boolean expression:

Code:
#include <iostream>
using namespace std;
int main() {
int num;
cout << "8-bit Binary Number=";
cin >> num;

[Code] .....

How can I get started with the body?

View 7 Replies View Related

C++ :: Convert Binary Number Into Decimal Number?

Jul 5, 2013

Here's the part of the codes where I tried to use boolean expression:

#include <iostream>
using namespace std;
int main()

[Code].....

May I know that how can I get started with the body?

View 5 Replies View Related

C++ :: Number Of Records In Binary File Is In Decimal?

Oct 9, 2014

My size of binary file is 1920 KB and my struct size is 124 kb. now to find number of records in file I divided 1920/124 and it gives me 15.4.... do I add 1 to 15.4 and make it 16 or do i take it as 15?

View 9 Replies View Related

C :: Convert Decimal Number To Binary And Store It In A String

Apr 16, 2014

I want to convert a decimal number to binary and store it in a string so that I can use that binary output for later computation. Here is what I did

Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()

[Code] ....

​Now as you can see that all the binary output is in a[] but how do I get it into a string so that I can use something like printf("%s",string) and get the binary output ?

View 7 Replies View Related

C :: Pass Decimal Number To Function And Convert It To Binary?

Feb 26, 2013

I'm trying to pass a decimal number to a function and convert it to binary and return it and print it out in main. But it prints out 1011 and then seg faults...not sure where it's tripping up

Code: int main(){
char* binNum = decToBin(25);
int i = 0;
while(binNum != NULL){

[Code].....

View 6 Replies View Related

C++ :: Random Number Generator Decimal To Binary System 0 To N

Mar 22, 2013

#include <iostream>
#include <stdlib.h>
using namespace std;

[Code]....

View 1 Replies View Related

Visual C++ :: Binary To Decimal Converter?

Oct 5, 2014

I'm trying to figure out why the binary to decimal part is not working correctly when the binary value finishes with a 1. In those cases, the decimal value shown in one unit smaller than it should be.

Code:

#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
void Binary_to_Decimal(), Decimal_to_Binary(); //prototype for the 2 functions that contain the converters
int main() //the menu {
int a_Choice;
cout << "Enter 1 - for binary to decimal" << endl;
cout << "Enter 2 - for decimal to binary" << endl;

[code]....

View 2 Replies View Related

C :: User Defined Number Of Decimal Places?

Sep 2, 2013

I need the user to be able to input the number of decimal places they wish to have displayed in the output. Everything works fine as is, I just don't know how to allow for the user to input the number of decimal places they want the output to have.

Code:

#include<stdio.h>
#include<math.h>
#define PI 3.141592654
int main(void) {
//Local Declarations
int x; //desired number of decimal places
float radius; //radius of circle
float circumference; //circumference of circle

[Code] .....

View 2 Replies View Related

C/C++ :: Converting Two Digit Hexadecimal Number To Binary Representation

Jan 25, 2014

The program is supposed to convert a two digit hexadecimal number to its binary representation. My code runs without any problems but I do not know how to limit the user's input to two digits only. For example the person can input "1ABC" and the program will give the binary representation and I need it to only accept two digit only like for example "1A".

#include<stdio.h>
#define MAX 1000
int main(){
char binaryNumber[MAX],hexaDecimal[MAX];
long int i=0;
printf("Enter a two digit hexadecimal number: ");

[Code] ....

View 8 Replies View Related

C/C++ :: Converting Number Into Binary Or Hexadecimal Or Octal Using Arrays

Mar 1, 2013

Write a program in c++ to accept a number and convert this number into binary or hexa decimal or octal number according to the user choice using the concept of array.

View 6 Replies View Related

Visual C++ :: Allowing User To Input Decimal?

Oct 21, 2013

This code is near complete, the only task that is left is allowing the user to input a decimal and then two integers, or automatically using .00 decimal.

The automatic part: /*This is not correct.

printf(".%.2d
", number);
*/

But that does no good for me. Question: Do I have to create a some sort of while loop again, to allow the user to input a decimal followed by integer?

Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
int j , i = 0, k = 0;
int number;

[code]....

View 1 Replies View Related

Visual C++ :: Taking Decimal Input From The User

Feb 21, 2015

I want the input for the price in decimal format(15.00). If the input is in integer format then I want to convert it to decimal format.

The maximum price for a sale is 999.99 and minimum is 0.00.

I have tried so far:

Code:
#include<iostream>
using std::cout;
using std::cin;
void main(){
float eventPrice;

[Code] .....

A valid input will be:

1.8,
0.8,
0.00,
0,
9,
99

View 2 Replies View Related

C/C++ :: Converting From Float To Decimal?

Sep 11, 2014

Question: A computer uses 10 bits to store integers with 1 bit for a sign. It stores an approximation of real numbers in 10 bits. The first bit of the first five is the sign of the mantissa and the other four bits are the mantissa. The first bit of the second five is the sign of the exponent and the other four the exponent.

1)What is the range of integers?

2)what is the range of real numbers(Float Type)

The first question was simple. I just found the smallest 10 digit binary number 1000000000 = -512 and then found the largest 10 digit binary number which would have to be 0111111111 = 511, therefore the range of integers is from -512 to 511.

For the second question - I am either making this harder than it is, or it really is a challenging question. So I followed the steps and first I was thinking I would take the number 1000000000 and convert this to a decimal (assuming its a 10 bit float)...But, can you even do this with a 10 bit float??

I ended up getting 1000000000 (after denormalizing) = .000100000 = 0.625.. would that be the minimum range? If so, then I know what I need to do to find the maximum , but if not - then I am really lost.

My Process was:

1.00000 X 2^(-4) = my final result of 0.625 after converting.

View 9 Replies View Related

C/C++ :: Converting A Fraction To Decimal?

Apr 28, 2015

i am having issues converting a fraction to a decimal, i think the code would go in the istream because it is working with input data but i just cant figure it out.

#include <cstdio>
#include <string>
#include <iostream>
using namespace std;

[Code].....

View 2 Replies View Related

C# :: Converting Decimal To Hexadecimal

Feb 20, 2015

I am new at programming and I have some questions about converting decimal to hexadecimal WITHOUT using .net library. The problem is, that I don't know how to do vice versa. (if you type 1254, program returns 6,14,4. I want programm to return 4,14,6- this is almost hexadecimal number (14 is not converted to "E")). Also the task is, that program has to return value in string form.

static void Main(string[] args) {
int a = 0;
int result = 0;
int n=1000000;
int[] array = new int[n];
Console.WriteLine("Insert numbers");
a = int.Parse(Console.ReadLine());

[Code] ....

View 12 Replies View Related

C++ ::  Converting Feet To Inches As A Decimal

Oct 21, 2014

I have my program all but done, but I can't get past this last part. I need to have the user input their height as a decimal. For example someone who is 5 foot 11 inches would need to enter it as 5.11, then I need to display there height in inches. Since i'm 5 foot 11, I would need to enter 5.11, then have it display 71 inches.

View 4 Replies View Related

C++ :: Input Decimal Number And Output To Be Number Scientific Notation

Apr 26, 2013

I need to write a code in c++ , to input decimal number and the output to be number in Scientific notation with 32 bits .

View 1 Replies View Related

C :: Decimal To Binary Using Bitwise

Nov 15, 2013

How to do this program i can easily do it in a simple for loop but i have to do this program with the following directions:

1. Write a function called bitN() that returns the value of bit N in number, where number is the first parameter, and N is the second. Assume N of the least significant bit is zero and that both parameters are unsigned int's. (A simple one-liner will suffice)

2. Write a main() function that uses bitN() to convert a decimal integer into its binary equivalent. Obtain the integer to convert from the first command-line argument.

3. Use the expression
unsigned int numBits = sizeof(unsigned int)*CHAR_BIT;
to get the number of bits in an unsigned int. (Include limits.h to get the definition for CHAR_BIT.)

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved