#include <codeword.h>
Collaboration diagram for ExtraLongUInt:

Public Types | |
| enum | { size = 2 } |
Public Member Functions | |
| ExtraLongUInt () | |
| ExtraLongUInt (const char *val) | |
| ExtraLongUInt (int val) | |
| ExtraLongUInt (unsigned int val) | |
| ExtraLongUInt (unsigned long val) | |
| bool | operator== (const ExtraLongUInt &other) const |
| bool | operator!= (const ExtraLongUInt &other) const |
| bool | operator< (const ExtraLongUInt &other) const |
| bool | operator> (const ExtraLongUInt &other) const |
| bool | operator<= (const ExtraLongUInt &other) const |
| bool | operator>= (const ExtraLongUInt &other) const |
| ExtraLongUInt | operator+ (const ExtraLongUInt &other) const |
| ExtraLongUInt | operator- (const ExtraLongUInt &other) const |
| ExtraLongUInt | operator & (const ExtraLongUInt &other) const |
| ExtraLongUInt | operator| (const ExtraLongUInt &other) const |
| ExtraLongUInt | operator^ (const ExtraLongUInt &other) const |
| ExtraLongUInt | operator~ () const |
| bool | operator! () const |
| ExtraLongUInt | operator<< (unsigned int bits) const |
| ExtraLongUInt | operator<< (const ExtraLongUInt &bits) const |
| ExtraLongUInt | operator>> (unsigned int bits) const |
| ExtraLongUInt | operator>> (const ExtraLongUInt &bits) const |
| const ExtraLongUInt & | operator<<= (unsigned int bits) |
| const ExtraLongUInt & | operator>>= (unsigned int bits) |
| const ExtraLongUInt & | operator &= (const ExtraLongUInt &other) |
| const ExtraLongUInt & | operator|= (const ExtraLongUInt &other) |
| const ExtraLongUInt & | operator^= (const ExtraLongUInt &other) |
| void | print (char *buf) const |
| unsigned int | bitcount () const |
| unsigned int | minbit () const |
Protected Attributes | |
| unsigned long | value [size] |
|
|
Definition at line 62 of file codeword.h.
00062 { size = 2 }; // determines size of value (in units of unsigned long).
|
|
|
Definition at line 257 of file codeword.cc. References value.
00258 {
00259 memset(value, 0, sizeof(value));
00260 }
|
|
|
Definition at line 263 of file codeword.cc.
00264 {
00265 const unsigned int len = strlen(val);
00266 char digit;
00267
00268 assert(len <= 8 * sizeof(value)); // or else overflow
00269 memset(value, 0, sizeof(value));
00270 for(unsigned int i = 0; i < len; ++i) {
00271 digit = val[len - 1 - i];
00272 assert(digit == '0' || digit == '1'); // or else val is not a binary number
00273 if(digit == '1') {
00274 value[i / (8 * sizeof(unsigned long))] |=
00275 (unsigned long) 1 << (i % (8 * sizeof(unsigned long)));
00276 }
00277 }
00278 }
|
|
|
Definition at line 281 of file codeword.cc. References value.
00282 {
00283 assert(val >= 0);
00284 memset(value, 0, sizeof(value));
00285 value[0] = val;
00286 }
|
|
|
Definition at line 289 of file codeword.cc. References value.
00290 {
00291 memset(value, 0, sizeof(value));
00292 value[0] = val;
00293 }
|
|
|
Definition at line 296 of file codeword.cc. References value.
00297 {
00298 memset(value, 0, sizeof(value));
00299 value[0] = val;
00300 }
|
|
|
Definition at line 526 of file codeword.cc. References value. Referenced by bitcount().
|
|
|
Definition at line 535 of file codeword.cc. References value. Referenced by minbit().
|
|
|
Definition at line 371 of file codeword.cc. References value.
00372 {
00373 ExtraLongUInt res;
00374
00375 for(unsigned int i = 0; i < sizeof(value) / sizeof(unsigned long); ++i) {
00376 res.value[i] = value[i] & other.value[i];
00377 }
00378 return res;
00379 }
|
|
|
Definition at line 493 of file codeword.cc.
00494 {
00495 *this = *this & other;
00496 return *this;
00497 }
|
|
|
Definition at line 411 of file codeword.cc. References value.
|
|
|
Definition at line 312 of file codeword.cc.
00313 {
00314 return (*this == other) ? false : true;
00315 }
|
|
|
Definition at line 347 of file codeword.cc. References value.
00348 {
00349 ExtraLongUInt res = 0;
00350 unsigned long c = 0;
00351 const int shift = 8 * sizeof(unsigned long) - 1;
00352 const unsigned long msb_mask = (unsigned long) 1 << shift;
00353 const unsigned long lsbs_mask = ~msb_mask;
00354 unsigned long x, y;
00355
00356 for(unsigned int i = 0; i < sizeof(value) / sizeof(unsigned long); ++i) {
00357 x = value[i];
00358 y = other.value[i];
00359 res.value[i] = (x & lsbs_mask) + (y & lsbs_mask) + c;
00360 c = ((x >> shift) + (y >> shift) + (res.value[i] >> shift)) >> 1;
00361 res.value[i] ^= (x & msb_mask) ^ (y & msb_mask);
00362 }
00363 return res;
00364 }
|
|
|
Definition at line 366 of file codeword.cc.
00367 {
00368 return *this + ~other + 1;
00369 }
|
|
|
Definition at line 317 of file codeword.cc. References value.
|
|
|
Definition at line 471 of file codeword.cc. References value.
00472 {
00473 return *this << bits.value[0];
00474 }
|
|
|
Definition at line 421 of file codeword.cc. References value.
00422 {
00423 ExtraLongUInt res = 0;
00424 const int index = bits / (8 * sizeof(unsigned long));
00425 const int shifts = bits % (8 * sizeof(unsigned long));
00426 unsigned int i;
00427
00428 if(sizeof(value) > index * sizeof(unsigned long)) {
00429 if(shifts == 0) { // this is because (1 >> 32) is not 0 (gcc)
00430 memcpy(&res.value[index],
00431 value,
00432 sizeof(value) - index * sizeof(unsigned long));
00433 } else {
00434 const unsigned long mask = (~(unsigned long) 0) >> shifts;
00435 assert(sizeof(value) >= sizeof(unsigned long));
00436 res.value[index] = (value[0] & mask) << shifts;
00437 for(i = index + 1; i < sizeof(value) / sizeof(unsigned long); ++i) {
00438 res.value[i] = ((value[i - index ] & mask) << shifts) |
00439 (value[i - index-1] >> ((8 * sizeof(unsigned long)) - shifts));
00440 }
00441 }
00442 }
00443 return res;
00444 }
|
|
|
Definition at line 481 of file codeword.cc.
00482 {
00483 *this = *this << bits;
00484 return *this;
00485 }
|
|
|
Definition at line 337 of file codeword.cc.
00338 {
00339 return (*this > other) ? false : true;
00340 }
|
|
|
Definition at line 302 of file codeword.cc. References value.
|
|
|
Definition at line 327 of file codeword.cc. References value.
|
|
|
Definition at line 342 of file codeword.cc.
00343 {
00344 return (*this < other) ? false : true;
00345 }
|
|
|
Definition at line 476 of file codeword.cc. References value.
00477 {
00478 return *this >> bits.value[0];
00479 }
|
|
|
Definition at line 446 of file codeword.cc. References value.
00447 {
00448 ExtraLongUInt res = 0;
00449 const int index = bits / (8 * sizeof(unsigned long));
00450 const int shifts = bits % (8 * sizeof(unsigned long));
00451 unsigned int i;
00452
00453 if(sizeof(value) > index * sizeof(unsigned long)) {
00454 if(shifts == 0) { // this is because (1 >> 32) is not 0 (gcc)
00455 memcpy(res.value,
00456 &value[index],
00457 sizeof(value) - index * sizeof(unsigned long));
00458 } else {
00459 const unsigned long mask = (~(unsigned long) 0) >> (8 * sizeof(unsigned long) - shifts);
00460 assert(sizeof(value) >= sizeof(unsigned long));
00461 for(i = 0; i < sizeof(value) / sizeof(unsigned long) - index - 1; ++i) {
00462 res.value[i] = (value[i+index ] >> shifts) |
00463 ((value[i+index+1] & mask) << ((8 * sizeof(unsigned long)) - shifts));
00464 }
00465 res.value[i] = value[i+index] >> shifts;
00466 }
00467 }
00468 return res;
00469 }
|
|
|
Definition at line 487 of file codeword.cc.
00488 {
00489 *this = *this >> bits;
00490 return *this;
00491 }
|
|
|
Definition at line 391 of file codeword.cc. References value.
00392 {
00393 ExtraLongUInt res;
00394
00395 for(unsigned int i = 0; i < sizeof(value) / sizeof(unsigned long); ++i) {
00396 res.value[i] = value[i] ^ other.value[i];
00397 }
00398 return res;
00399 }
|
|
|
Definition at line 505 of file codeword.cc.
00506 {
00507 *this = *this ^ other;
00508 return *this;
00509 }
|
|
|
Definition at line 381 of file codeword.cc. References value.
00382 {
00383 ExtraLongUInt res;
00384
00385 for(unsigned int i = 0; i < sizeof(value) / sizeof(unsigned long); ++i) {
00386 res.value[i] = value[i] | other.value[i];
00387 }
00388 return res;
00389 }
|
|
|
Definition at line 499 of file codeword.cc.
00500 {
00501 *this = *this | other;
00502 return *this;
00503 }
|
|
|
Definition at line 401 of file codeword.cc. References value.
00402 {
00403 ExtraLongUInt res;
00404
00405 for(unsigned int i = 0; i < sizeof(value) / sizeof(unsigned long); ++i) {
00406 res.value[i] = ~value[i];
00407 }
00408 return res;
00409 }
|
|
|
Definition at line 511 of file codeword.cc. References value. Referenced by MFTPRcvAgent::recv_data(), and MFTPSndAgent::send_data().
00512 {
00513 int i, fin;
00514
00515 for(i = 8 * sizeof(value) - 1; !(value[i / (8 * sizeof(unsigned long))] &
00516 ((unsigned long) 1 << (i % (8 * sizeof(unsigned long))))) && i > 0; --i)
00517 ;
00518 for(fin = i; i >= 0; --i) {
00519 buf[fin-i] = (value[i / (8 * sizeof(unsigned long))] &
00520 (unsigned long) 1 << (i % (8 * sizeof(unsigned long)))) ?
00521 '1' : '0';
00522 }
00523 buf[fin+1] = '\0';
00524 }
|
|
|
Definition at line 65 of file codeword.h. Referenced by bitcount(), ExtraLongUInt(), minbit(), operator &(), operator!(), operator+(), operator<(), operator<<(), operator==(), operator>(), operator>>(), operator^(), operator|(), operator~(), and print(). |
1.3.3