Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Mar 25, 1999

Short Vs. Int and Number Conversion

Question:
1) What is the difference between a int and a short variable? 2) How do I convert a number to binary from decimal?

Answer:
1. Depending on the platform, some C compilers will implement an int as a short (16-bits) while other compilers will implement an int as a long (32-bits). Declaring a variable as a short assures it uses 16-bit regardless of the platform.

2. I see this question a lot. However, it really doesn't make much sense to me as stated. This is because all information is stored in computers as binary, so how can you convert to binary? If you mean, how can you take a binary number and convert it to a string in binary format then I can tell you most compilers don't appear to support this and it would take a small routine like this:

#include 
#include 
#include 
#include 

void main()
{
   char buff[21];

   itoa(33, buff, 2);
   cout << buff;
}
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date