1 /** 2 * Describes common utility functions shared between CPER projects within this repository. 3 * No functions here depend on json-c or b64.c. 4 * 5 * Author: Lawrence.Tang@arm.com 6 **/ 7 8 #include "edk/BaseTypes.h" 9 #include "common-utils.h" 10 11 //Converts the given BCD byte to a standard integer. 12 int bcd_to_int(UINT8 bcd) 13 { 14 return ((bcd & 0xF0) >> 4) * 10 + (bcd & 0x0F); 15 } 16 17 //Converts the given integer to a single byte BCD. 18 UINT8 int_to_bcd(int value) 19 { 20 UINT8 result = 0; 21 int shift = 0; 22 while (value > 0) { 23 result |= (value % 10) << (shift++ << 2); 24 value /= 10; 25 } 26 27 return result; 28 } 29