1 /*############################################################################ 2 # Copyright 2017 Intel Corporation 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 ############################################################################*/ 16 /// Convert values between host and big-/little-endian byte order. 17 /*! \file */ 18 19 #ifndef EPID_MEMBER_TINY_STDLIB_ENDIAN_H_ 20 #define EPID_MEMBER_TINY_STDLIB_ENDIAN_H_ 21 22 #include <stdint.h> 23 24 /// Transform big endian uint32_t to host uint32_t 25 #define be32toh(big_endian_32bits) \ 26 ((uint32_t)(((((unsigned char*)&(big_endian_32bits))[0]) << 24) + \ 27 ((((unsigned char*)&(big_endian_32bits))[1]) << 16) + \ 28 ((((unsigned char*)&(big_endian_32bits))[2]) << 8) + \ 29 (((unsigned char*)&(big_endian_32bits))[3]))) 30 31 /// Transform host uint32_t to big endian uint32_t 32 #define htobe32(host_32bits) \ 33 (uint32_t)(((((uint32_t)(host_32bits)) & 0xFF) << 24) | \ 34 ((((uint32_t)(host_32bits)) & 0xFF00) << 8) | \ 35 ((((uint32_t)(host_32bits)) & 0xFF0000) >> 8) | \ 36 ((((uint32_t)(host_32bits)) & 0xFF000000) >> 24)) 37 38 #endif // EPID_MEMBER_TINY_STDLIB_ENDIAN_H_ 39