Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
16 bit, 32 bit, why should I care?
#1
Can anyone tell me what the difference in C++ is between a long, short, and float is? And what difference does being 32 bit and 16 bit make?
Reply
#2
short = short integer, typically 16 bits on an x86. Signed ranges from -32768 to 32767, unsigned from 0 to 65535. Same as QB's INTEGER.
long = long integer, typically 32 bits on an x86. Signed ranges from -2,147,483,648 to 2,147,483,647, unsigned from 0 to 4,294,967,295. Same as QB's LONG.
float = floating point, typically 32 bits. Ranges -3.402823 x 10^38 to -1.401298 x 10^-45 for negative values and 1.401298 x 10^-45 to 3.402823 x 10^38 for positive values. Same as QB's SINGLE.
Reply
#3
Quote:Can anyone tell me what the difference in C++ is between a long, short, and float is? And what difference does being 32 bit and 16 bit make?

The other answer is likely correct for your hardware/software combination. Another solution, if you really need to make certian that a particular sized integer is used, you can include the c (not c++) header stdint.h and use it's well-defined types with names like uint32_t for an unsigned 32-bit integer. It is expected that this library will be a part of the next C++ standard revision.
Reply
#4
The difference betveen 16 and 32bit program is (I think, anyone correct me if I'm wrong) that they send different amount of data to the processor at a time, 16bits or 32bits..

A 32bit program cannot be run on a 16bit processor, thus some programs require a 386 (Which is 32bit)

There's also a 64bit processor available for the homePC now, forgot it's name though.
Reply
#5
I think he's talking about just data types, which are the number of bits a number can hold. you should care, because a number with more bits can be an exponentially higher value.

a long is a 32-bit integer, a short is a 16 bit integer, and a float is a 32-bit IEEE floating point integer (decimal), at least I think, I'm not concretely certain on all of this.

and speaking of "xx-bit cpus" that's referring to the size of the registers, the most basic unit of memory in a processor. if you've ever programmed asm, you send information to registers to perform each operation. larger registers mean you can perform more operations with larger numbers faster, and you can send bigger addresses, allowing for more memory. and since you can't send 32 bits to a cpu with 16-bit registers, no, you can't run a 32-bit program on a 16-bit cpu.

amd is already producing 64-bit cpus (athlon 64 or fx or something), and intel is waiting for a 64-bit windows release to ship their 64-bit cpus.
Reply
#6
The thing about the basic c integer datatypes is that they are not defined across platforms.

it is possible that a char, short, int, and long are *all* the same length...(eg 64-bit) There is actually no guarantee that a char is 8-bit!! If you want to be sure that a particular integer size will be used when your source is compiled on different compilers/different hardware platforms, things become somewhat tricky...which is why the stdint.h headder was introduced...as a replacement for the ambiguous bit-lengthed char, short, int, and long.

However...as has been said several times in this thread...

On current 32-bit Windows machines, when using current compilers,

char = 8-bit
short = 16-bit
int = 32-bit
long = 32-bit

However in the future you could easily find that int and long are 64-bit data-types...which would cause certian types of code to behave differently from the expected 32-bit types.

Actually, this is real easy to test on your platform with the sizeof function using something like (untested)
Code:
#include<iostream>

using std::cout;
using std::endl;

int main(){
  
  char  c;
  short s;
  int   i;
  long  l;
  
  cout << sizeof(c) * CHAR_BIT << endl
       << sizeof(s) * CHAR_BIT << endl
       << sizeof(i) * CHAR_BIT << endl
       << sizeof(l) * CHAR_BIT << endl;
  
  return 0;
}

hth
Reply
#7
As put very technically by plasma, long, short, float etc are used to store data of different ranges and types. Also remember, when you are using variables of same datatype in an expression, the execution speed is very high as compared to an expression containing variables of different datatypes =).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)