i understand the 0xff0f is a hexadecimal value(i don't know in decimal), but why these number and not other?
can anyone explain to me these 2 calculations?
(they are changed with SetConsoleTextAttribute() function)
Magic numbers for bit twiddling are typically chosen to be unique bit patterns. For example, in the case of flags that are intended to be OR'd together you'd typically want to choose numbers where a single bit is set:
That way when they're OR'd together, you get a bit pattern that can easily be tested with AND.
The problem with your question is that you shouldn't be using magic numbers at all. Rather, you should be OR'ing together the manifest constants for those flags, even if it's more verbose. The constants are there because the magic numbers could change, and then code that uses the magic numbers would break.
i don't know these calculations(someone did them for help me)... i need to understand them because seems to be used in very situations.
thanks for all, but please give more information about these type of calculations.
i need to understand them because seems to be used in very situations.
In this case you don't. Someone gave you bad advice.
please give more information about these type of calculations.
First you need to figure out what those magic numbers represent. It's harder because they're intended to be opaque and not worked with directly here. Once you find out what each of the constants you want to work with represent, it's simple enough to figure out what the bit operations do for you using the corresponding truth tables.
give me a link for read more about that magic numbers?
Magic numbers are just that, magic. They're selected completely at the discretion of the programmer, so there's really nothing to document in general about magic numbers beyond. A good library should hide any use of magic numbers from you anyway.
What I've been saying is that you need a very specific case to study, but this case is not a good one because merely using the magic numbers is a bad practice.
Instead, I think you'd be better off studying bit twiddling in general, rather than continuing with this specific usage. Try googling for "bit manipulation exercises".