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

Mar 21, 2013 at 10:48pm
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?
Mar 21, 2013 at 10:55pm
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.
Mar 21, 2013 at 11:04pm
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 Mar 21, 2013 at 11:05pm
Mar 22, 2013 at 12:05am
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.
Mar 22, 2013 at 12:16am
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... >:(
Mar 22, 2013 at 1:43am
I did not report your post, I don't know who reported us.
Mar 22, 2013 at 3:44am
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;
}
Mar 22, 2013 at 4:15am
Print to a binary file and then print that file.
Mar 22, 2013 at 4:18am
@buffbill

How do you make one of those?
Mar 22, 2013 at 4:20am
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.
Mar 22, 2013 at 8:39am
@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.