Printing data as it is stored in memory (binary)?

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?
closed account (jyU4izwU)
-_- 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.
Do you understand mathematically how to convert from any base to base 2?

@ibranext: please do not be rude, and please do not encourage using deprecated software.
Last edited on
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.
closed account (jyU4izwU)
@IndieExe and L B

Yes you can...

1=True
0=False

Youse Bool To Get Pass All The Complications And To L B I was Not Being Mean And Why Did You Report Me... >:(
I did not report your post, I don't know who reported us.
I believe there is a way to do that, but you will have to make your own function.

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
#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;
}
Print to a binary file and then print that file.
@buffbill

How do you make one of those?
closed account (N36fSL3A)
@ibranext you seem very cocky... When the fact is you can't event figure out how to use multiple classes. Don't put others down, seriously.
@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

Anyway, thank you all for your replies.
Topic archived. No new replies allowed.