Advertisement
Advertisement
| 03.11.2008 at 11:39AM PDT, ID: 23232803 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
|
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
| Microsoft |
| Apple |
| Internet |
| Gamers |
| Digital Living |
| Virus & Spyware |
| Hardware |
| Software |
| ITPro |
| Developer |
| Storage |
| OS |
| Database |
| Security |
| Programming |
| Web Development |
| Networking |
| Other |
| Community Support |
| 03.11.2008 at 11:47AM PDT, ID: 21098743 |
| 03.11.2008 at 11:49AM PDT, ID: 21098764 |
1: 2: 3: 4: 5: |
bool testBit( unsigned int bitField, int bitIndex )
{
unsigned int mask = 1 << bitIndex;
return bitField & mask;
}
|
| 03.11.2008 at 11:52AM PDT, ID: 21098796 |
| 03.11.2008 at 12:02PM PDT, ID: 21098901 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: |
#include <stdio.h>
union mybitfield
{
struct
{
unsigned short a : 4;
unsigned short b : 5;
unsigned short c : 7;
} field;
unsigned short value;
};
void main ()
{
mybitfield bf;
bf.field.a = 1;
if (bf.value != 0) printf("Some bit is set\n");
}
|
| 03.11.2008 at 12:03PM PDT, ID: 21098905 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: |
#include <cassert>
template <typename T>
bool test(T const & x)
{
T y = x - 1;
T z = ~y;
return ((z & y) + 1) == x;
}
int main()
{
assert(test(1)); // 1 bit
assert(test(2)); // 1 bit
assert(!test(3)); // 2 bits
assert(test(4)); // 1 bit
}
|
| 03.11.2008 at 12:06PM PDT, ID: 21098928 |
| 03.11.2008 at 12:07PM PDT, ID: 21098940 |
| 03.11.2008 at 12:14PM PDT, ID: 21099005 |
| 03.11.2008 at 12:20PM PDT, ID: 21099079 |
| 03.11.2008 at 12:23PM PDT, ID: 21099103 |
| 03.11.2008 at 12:26PM PDT, ID: 21099129 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: |
#include <cassert>
template <typename T>
bool test(T const & x)
{
return x && !(x & (x-1));
}
int main()
{
assert(!test(0)); // 0 bit
assert(test(1)); // 1 bit
assert(test(2)); // 1 bit
assert(!test(3)); // 2 bits
assert(test(4)); // 1 bit
}
|
| 03.11.2008 at 12:26PM PDT, ID: 21099131 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: |
template<typename T, int n>
struct mybitfield {
T a : n;
T b : n;
};
template<typename T,n>
bool test_any(const mybitfield<T,n>& bf) {
T* pt = (T*) &bf;
return *t != 0;
};
|
| 03.11.2008 at 12:48PM PDT, ID: 21099374 |
| 03.11.2008 at 01:01PM PDT, ID: 21099516 |
| 03.11.2008 at 02:17PM PDT, ID: 21100473 |
1: 2: 3: 4: 5: 6: 7: 8: 9: |
#define MASK(n) ((0x01 << (n)) - 1)
#define IS_1_BIT_SET(x) ((x) && !((x) & ((x) - 1)))
#define IS_N_BITS_SET(x, n) (!((x) % MASK(n)) && IS_1_BIT_SET((x) / MASK(n)))
unsigned int value; /* some value */
if (IS_N_BITS_SET(value, 3)) {
/* 3 consecutive bits are set in value */
}
|