The following code will convert any number in any base to any other base, from binary to hexadecimal, and everything inbetween.
#include<iostream>
#include<string>
#include<sstream>
typedef unsigned long long ull;
typedef unsigned long ul;
const std::string symbols="0123456789abcdef";
std::string inputvalue(ul base)
{
using namespace std;
string value;
while(1)
{
cout<<"Enter a positive value : ";
string s;
getline(cin,s);
if(s.size())
{
for(string::iterator i=s.begin();i!=s.end();++i)
if(*i>='A' && *i<='Z')
*i+=32;
string actual = symbols.substr(0,base);
if(s.find_first_not_of(actual)!=string::npos)
{
cout<<"The value you entered is invalid for the base.\n"
<<"Please enter another value.\n"<<endl;
continue;
}
value=s;
break;
}
}
return(value);
}
ul inputbase(std::string prompt)
{
using namespace std;
ul result=0, min=2, max=16;
while(1)
{
cout<<prompt.c_str()<<" ["<<min<<".."<<max<<"] : ";
string s;
getline(cin,s);
if(s.size())
result=stoul(s,0,10);
if(result<min result>max)
cout<<"The base must be in the range "
<<min<<".."<<max<<"\n"
<<"Please enter another base.\n"<<endl;
else
break;
}
return(result);
}
ull base2dec(std::string value,ul base)
{
ull col=1, num=0;
for(std::string::reverse_iterator i=value.rbegin(); i!=value.rend(); ++i)
{
num+=symbols.find(*i,0)*col;
col*=base;
}
return(num);
}
std::string dec2base(ull dec,ul base)
{
using namespace std;
int len=1;
ull tmp=dec;
while(tmp/=base)
++len;
string value("0",len);
while(dec)
{
value[--len]=symbols[dec%base];
dec/=base;
}
return(value);
}
int main()
{
using namespace std;
ul base=inputbase("Enter the base of the value");
string value=inputvalue(base);
ul newbase=inputbase("Enter the base to convert to");
value=dec2base(base2dec(value,base),newbase);
cout<<"New value:\t"<<value.c_str()<<endl;
return(0);
}
Use inline assembly instructions. Then compile your C++ program to produce the machine code.
C++ is high-level source code, while MIPS is low-level machine code for a reduced instruction set computer (RISC). To convert C++ source code to MIPS you need a C++ compiler specific to the MIPS architecture you're building against.
Its code of estonia
Divide it by 1000.
Char 'a' is 97 decimal (61 hex) while char 'A' is 65 decimal (41 hex), a difference of 32 decimal (20 hex). Therefore test each char value in the char array (or string) using a for loop. If the char value is in the range 'a' to 'z', then subtract 32 decimal (20 hex). The following example demonstrates the method: void toupper(char* str, int len) { for(int i=0; i<len; ++i) { if(str[i]>='a' && str[i]<='z') str[i]-=32; } } To convert from upper to lower case, use the following instead: void tolower(char* str, int len) { for(int i=0; i<len; ++i) { if(str[i]>='A' && str[i]<='Z') str[i]+=32; } }
easy, 1011. in binary of course. convert 1011 binary to decimal you get 11.
CDIX = 409 and XCV = 95, so 409 + 95 = 504 (DIV)
You cannot. C++ and shell script (which shell, by the way? there are more than one) are entirely different languages.
The number 5.9 is already in decimal form. We know that 5.9 is 5 plus 9/10. The 9/10 is 0.9, so 5 + 9/10 is 5.9 as already written in decimal form.
A negative decimal plus a negative decimal equals a more negative decimal
To convert a decimal into a fraction, we need to look at the decimal places. In this case, 2.9166666667 can be written as 2 whole units plus 0.9166666667. Since there are 10 decimal places in 0.9166666667, we can write it as 9166666667/10000000000. Therefore, the fraction equivalent of 2.9166666667 is 2 9166666667/10000000000.
0.85, here's how:1/2 = 0.501/4 = 0.251/10 = 0.10Add them together to get 0.85 You could also convert the fractions to common denominators first, to get 10/20 + 5/20 + 2/20 = 17/20, then convert that to get the same decimal (0.85).
Find 20% of 800. Divide the percentage by 100 to convert it to a decimal. You get 0.2. Then multiply the decimal by the amount. 0.2 x 800. You get 160. Then add this to the original amount. 800 + 160 = 960. Or to simplify this...you can just multiply 800 by 1.2 (1 plus the percentage in decimal form).
Use inline assembly instructions. Then compile your C++ program to produce the machine code.
If you want to add numbers in different bases, in this case decimal and binary, or do any other calculation that involves different bases for that matter, you have to convert all numbers to a single system first - for example, all to decimal. Then you can do the operation. It is really up to you in what base you represent the final answer. In this example, you can convert back to binary, for example.
no that's just 6 divided by 4 plus you cant divide a percent by a fraction unless you convert both into a decimal. the answer should be .24 because if you convert 1/4 into a decimal its .25 and 6% into a decimal is .06. When you divide .06 (the original 6%) by .25 (the original 1/4 fraction) you get the answer of .24
Convert to same types to give six tenths and five tenths. That is eleven tenths. That is one and one tenth or 1.1 in decimal.