Arduino Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
checksum.hpp
Go to the documentation of this file.
1 // Author: Mario S. Könz <mskoenz@gmx.net>
2 // Date: 15.06.2013 17:18:44 EDT
3 // File: checksum.hpp
4 
5 /* This program is free software. It comes without any warranty, to
6  * the extent permitted by applicable law. You can redistribute it
7  * and/or modify it under the terms of the Do What The Fuck You Want
8  * To Public License, Version 2, as published by Sam Hocevar. See
9  * http://www.wtfpl.net/ or COPYING for more details. */
10 
11 #ifndef __CHECKSUM_HEADER
12 #define __CHECKSUM_HEADER
13 
14 namespace util {
15  //------------------- checksum generator -------------------
16  template<typename T>
17  uint8_t checksum(T const & t) {
18  uint8_t res = 0;
19  uint8_t const * const p = (uint8_t*)(&t);
20  for(uint16_t i = 0; i < sizeof(t); ++i) {
21  res += p[i];
22  }
23  return res;
24  }
25 }//end namespace util
26 
27 #endif //__CHECKSUM_HEADER
uint8_t checksum(T const &t)
Definition: checksum.hpp:17