* Gaijinco:
Is there any way to declare a variable as a binary so that if the
variable "var" holds the value of 1001, then ++var = 1010?
Binary, decimal, hexadecimal, roman numerals and so on are presentation
formats: how values are _presented_ by the system, or input to the system.
In C++ all built-in integer types are binary in the sense that the language
provides some operations that operate directly on the binary digits.
However, that does not mean they are necessarily binary in the sense of the
binary number system, although (with a slight modification for signed types)
that is a very reasonable assumption, and one extremely unlikely to be wrong.
Consider the following program:
#include <iostream> // std::cout
#include <ostream> // <<, std::endl
#include <bitset> // std::bitset
int main()
{
typedef std::bitset<4> FourBits;
int x;
x = 9; // Binary 1001.
std::cout << FourBits( x ) << std::endl;
++x;
std::cout << FourBits( x ) << std::endl;
}
The output here is 1001 and 1010, so '++x' does exactly what you want.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?