Advertisement
TShiva

UInt24_t

Jun 7th, 2019
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #pragma once
  2.  
  3. /*
  4. class UInt24_t
  5. {
  6. private:
  7.     const int Uint24_t_MAX = 16777215;
  8.     const int Uint24_t_MIN = 0;
  9.     unsigned char value[3];
  10. public:
  11.     UInt24_t(){};
  12.  
  13.     UInt24_t(UInt24_t& val)
  14.     {
  15.         *this = val;
  16.     }
  17.  
  18.     template <typename T>
  19.     UInt24_t(T& val)
  20.     {
  21.         (0xff << 24) | (value[2] << 16)
  22.                      | (value[1] << 8)
  23.                      | value[0];
  24.         *this = val;
  25.     }
  26.  
  27.     operator unsigned int(){
  28.         return (0xff << 24) | (value[2] << 16)
  29.                             | (value[1] << 8)
  30.                             | value[0];
  31.     }
  32.  
  33.     UInt24_t& operator= (const UInt24_t& input)
  34.     {
  35.         value[0] = input.value[0];
  36.         value[1] = input.value[1];
  37.         value[2] = input.value[2];
  38.         return *this;
  39.     }
  40.  
  41.     //template<typename T>
  42.     UInt24_t& operator= (unsigned int input)
  43.     {
  44.         value[0] = reinterpret_cast<unsigned char*>(&input)[0];
  45.         value[1] = reinterpret_cast<unsigned char*>(&input)[1];
  46.         value[2] = reinterpret_cast<unsigned char*>(&input)[2];
  47.         return *this;
  48.     }
  49.  
  50.     UInt24_t operator+(UInt24_t& input)
  51.     {
  52.         unsigned int cock0 = reinterpret_cast<unsigned int>(this*) + static_cast<unsigned int>(input);
  53.         auto cock = UInt24_t(cock0);
  54.         return cock;
  55.     }
  56.  
  57.     UInt24_t operator- (const UInt24_t& val) const
  58.     {
  59.         return UInt24_t((unsigned int)*this - (unsigned int)val);
  60.     }
  61.  
  62.  
  63.  
  64.     ~UInt24_t();
  65. };
  66. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement