newbie questions

C

Connor Clark

1. How do I find the value of a variable in BYTES instead of getting the
normal data it stores. IE

int a = 23;

cout<<bytevalue(a);


would print some string in binary.

2. Is there an easy way to convert between binary, decimal, and hexadecimal?


Thanks, and sorry in advance if I'm posting in the wrong place and/or doing
something else totally wrong, I've never used a newsgroup before.
 
L

Larry I Smith

Connor said:
1. How do I find the value of a variable in BYTES instead of getting the
normal data it stores. IE

int a = 23;

cout<<bytevalue(a);


would print some string in binary.

2. Is there an easy way to convert between binary, decimal, and hexadecimal?


Thanks, and sorry in advance if I'm posting in the wrong place and/or doing
something else totally wrong, I've never used a newsgroup before.

Here's some examples:

#include <iostream>
#include <bitset>

int main()
{
int a = 23;

std::cout << "dec " << a << " = hex " << std::hex << a
<< " = octal " << std::eek:ct << a << std::endl;

std::cout << "as a 32 bit binary "
<< std::bitset<32>(a) << std::endl;

return 0;
}

The output should be:

dec 23 = hex 17 = octal 27
as a 32 bit binary 00000000000000000000000000010111

Regards,
Larry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top