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
ADVERTISEMENT
Jan 28, 2014
I am working on an assignment about converting an integer number to its 2's complement presentation. The binary representation is consisting of a single linked list.
As we all know, the steps of this converting is to taking the reminder of the absolute value, then flipping the 1 to be 0, and the 0 to be 1 in the binary number. And the last step will be to add 1 to the binary number invers.
I wrote a code that implements every thin correctly. However, when I reached the part of adding 1, the program was hanged.
int Absolute; //the first step is to convert the number to the binry reprezentation
Absolute = abs (value);// by take the Absolute value of the negative number, then find the
while (Absolute !=0) //the binary reprezentation {
int res;
res= (Absolute % 2);
pushFront (res);
Absolute /=2 ;
[Code] .....
View 11 Replies
View Related
Oct 12, 2013
You enter decimal number into the program and what base you want. The integer part of the decimal is being handled fine, but the decimal is not.
For example, I enter 15.6847 and base 10, which means I'm going from base 10 to base 10. It spits out 68469999999999 for the decimal part. (Do not worry about the first block of numbers. The second block seperated from the first by a space is where the decimal will appear in order.)
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int baseConverter(int, int, int *, int *);
[Code] ....
View 2 Replies
View Related
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
View Related
Mar 25, 2013
I got this algorithm of conversion and now I'm stuck at how to code it.
"Algorithm to Convert From any Base to Base 10 Decimal."
Let 'n' be the number of digits in the number. For example, 104 has 3 digits, so 'n'=3.
Let 'b' be the base of the number. For example, 104 is decimal so 'b' = 10.
Let 's' be a running total, initially 0.
For each digit in the number, working left to right do:
Subtract 1 from 'n'.
Multiply the digit times b^n and add it to 's'.
When done with all the digits in the number, the decimal value should be 's' .
View 6 Replies
View Related
Mar 3, 2014
In this exercise:The C Programming Language Exercise 3-4..It states the following: "In a two's complement number representation, our version of itoa does not handle the largest negative number, that is, the value of n equal to -(2 to the power (wordsize - 1)) ."
A char is one byte (255 bits). The range of an 8 bit variable using a two's complement representation is -128 to 127. Therefore -128 is the largest negative value. The statement in book suggests that the itoa function will not output -128 if we pass -128 as a parameter, because in itoa when we try to convert -128 to positive -128, the inverse of -128 is -128. However, I just ran this code in my computer and it successfully outputted -128.
Code:
#include <stdio.h>
#include <string.h>
#define SIZE 10
void reverse(char s[])
{
int c, i, j;
}
[code].....
View 2 Replies
View Related
Dec 7, 2014
I had an exercise to convert from decimal to binary with base 2, it was simple simple i did the following:
Code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
void Conversion (int n);
[Code] .....
I then had an follow up exercise which was to replicate but for any base up to 10, i thought i would just have to replace 2 with a variable obtained from the user, however this did not work as i got an error saying too few arguments function but i cannot see why i am getting this.
Code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
float Conversion (int n, int b);
[Code] ......
View 5 Replies
View Related
Jan 30, 2013
I had the idea to write a program that would convert a decimal integer into any base up to 36 (there are no letters after that) so I decided to give it a try.
Code:
#include <stdio.h>
#include <stdlib.h>
char letters(int r); // prototypes function for converting 10's to A's and so on, base 11+ will work
int main() {
int base;
int d; //declares decimal integer
int d_clone; // clones d for a loop
[Code] ......
View 8 Replies
View Related
Jun 14, 2014
I have written this function.
void intToBase(unsigned int val,char *buff, unsigned int base) {
int digit = val%base;
if(val == 0)
return;
intToBase((val / base), buff + 1, base);
if(digit >= 0 && digit <= 9)
*buff = (digit + '0');
if(digit >= 10 && digit <= 15)
*buff = (digit + 'A' - 10);
}
This function is suppose to convert a decimal number (val) to any other base number and put it into a string (buff).
But the function puts the value in a opposite way, like if the answer is suppose to be "123" i get this "321".
Note: the function must be recursive and i can't use loops.
View 1 Replies
View Related
Apr 15, 2013
How would you convert say "238273615237287352536266362524382737272" base 10 to a base x number contained within a string of characters?
View 2 Replies
View Related
Oct 6, 2014
I need to create a generic function that changes from any starting base, to any final base. I have everything down, except my original function took (and takes) an int value for the number that it converts to another base. I decided to just overload the function. I am Ok with changing between every base, but am slightly off when using my new function to take in a string hex value.
The code below should output 1235 for both functions. It does for the first one, but for the second, I am currently getting 1347. Decimal to Hex works fine - It's just the overloaded function (Hex to anything else) that is slightly off.
#include <iostream>
#include <stack>
#include <string>
#include <cmath>
using namespace std;
void switchBasesFunction(stack<int> & myStack, int startBase, int finalBase, int num);
void switchBasesFunction(stack<int> & myStack, int startBase, int finalBase, string s);
[Code] .....
View 2 Replies
View Related
May 7, 2013
i am converting a base 10 number to base 4.
View 1 Replies
View Related
Feb 8, 2013
I was wondering if there is a standard for converting something like this:
HELLO 27 to ?3
View 5 Replies
View Related
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
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
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
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
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
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
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
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
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
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
Jun 20, 2013
User enters sentence "The Smiths have two daughters, three sons, two cats and one dog." (The numbers may change depending on what the user chooses to enter. He told us the range would be from zero to nine.) and we have to convert the written numbers within the sentence into actual decimal numbers and print out the new sentence. Ex. The Smiths have 2 daughters, 3 sons...etc.
I have written the following bit of code which reads the string and finds all the "written numbers" but I am not sure how to proceed from there. I am stuck on how to print out the new sentence with the converted numbers as my professor mentioned something about creating the new string using dynamic memory allocation.
Code:
#include <stdio.h>#include <string.h>
int main () {
char A[100];
int length = 0;
int i;
[Code] .....
View 7 Replies
View Related
Jul 23, 2014
I am using MCC18 for use with MPLAB.
0bnnnnnnnn means a binary representation.
0x00 means a hex number representation.
What does sd001 means? signed decimal 1? if so how do I represent a -1 using this sdnnnn format?
View 3 Replies
View Related
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