Before you yell at me to use the search bar you need to know that I did but didn't find anything that actually works (either that or the answers were too obvious for me to understand).
So, if I'm right, computer store their data as binary values. So if I write int x = 5; , my computer converts the value of x from decimal (5) into binary (101) and stores it in memory as a a binary number. If I print that value on the screen that value is converted(by default) back into a decimal number before being printed on the screen.
Now, my question is if there is any way to print the value of x directly into binary(as it's stored in memory) without it being converted back into a decimal value?
-_- fail... This is so easy and im only 14... well you are looking for the integral of x5 right soo... Its Not Possible. you cant change it while it or is not printed you will have to get Turbo C++ For it to work, if you do It Will Most Likely Work.
Now, my question is if there is any way to print the value of x directly into binary(as it's stored in memory) without it being converted back into a decimal value?
Not directly with std::cout
However, you can easily make a conversion function using a type char* to store the character
constants of '1' and '0'.
Then print the value with std::cout<<ToBinary(number);
HINT: This may or may not involve char*, your choise.
#include <cstdio>
#define isbetween(A,B,C)((A <= B) && (B <= C))
void convert_base(int V, int base)
{
if (V)
{
convert_base(V/base, base);
printf("%d",V%base);
}
}
int main()
{
int num, b;
while(1)
{
puts("\nEnter a number");
scanf("%d", &num);
puts("Enter a base to convert to (2-10)");
scanf("%d", &b);
if (isbetween(2,b,10))
convert_base(num, b);
}
return 0;
}
@L B Yes, yes I do. In fact I have no problem converting from base to base using my own written functions, I was just wondering if I can do so directly without using them just as I can do with hex and octal:printf("%x",14) or cout << hex << 14