Botan  1.11.15
src/lib/utils/get_byte.h
Go to the documentation of this file.
00001 /*
00002 * Read out bytes
00003 * (C) 1999-2007 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_GET_BYTE_H__
00009 #define BOTAN_GET_BYTE_H__
00010 
00011 #include <botan/types.h>
00012 
00013 namespace Botan {
00014 
00015 /**
00016 * Byte extraction
00017 * @param byte_num which byte to extract, 0 == highest byte
00018 * @param input the value to extract from
00019 * @return byte byte_num of input
00020 */
00021 template<typename T> inline byte get_byte(size_t byte_num, T input)
00022    {
00023    return static_cast<byte>(
00024       input >> ((sizeof(T)-1-(byte_num&(sizeof(T)-1))) << 3)
00025       );
00026    }
00027 
00028 }
00029 
00030 #endif