Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "amtec_conversion.h"
00038
00039 int ParamBytes(int type)
00040 {
00041 switch(type) {
00042 case INT8:
00043 return(1);
00044 break;
00045 case UINT8:
00046 return(1);
00047 break;
00048 case INT16:
00049 return(2);
00050 break;
00051 case UINT16:
00052 return(2);
00053 break;
00054 case INT32:
00055 return(4);
00056 break;
00057 case UINT32:
00058 return(4);
00059 break;
00060 case FLOAT:
00061 return(4);
00062 break;
00063 }
00064 return(0);
00065 }
00066
00067
00068
00069 char convertBytes2Int8(unsigned char *bytes)
00070 {
00071 char i;
00072 memcpy(&i, bytes, sizeof(char));
00073 return(i);
00074 }
00075
00076 unsigned char convertBytes2UInt8(unsigned char *bytes)
00077 {
00078 unsigned char i;
00079 memcpy(&i, bytes, sizeof(unsigned char));
00080 return(i);
00081 }
00082
00083 short convertBytes2Int16(unsigned char *bytes)
00084 {
00085 short i;
00086 memcpy(&i, bytes, sizeof(short));
00087 return(i);
00088 }
00089
00090 unsigned short convertBytes2UInt16(unsigned char *bytes)
00091 {
00092 unsigned short i;
00093 memcpy(&i, bytes, sizeof(unsigned short));
00094 return(i);
00095 }
00096
00097 int convertBytes2Int32(unsigned char *bytes)
00098 {
00099 int i;
00100 memcpy(&i, bytes, sizeof(int));
00101 return(i);
00102 }
00103
00104 unsigned int convertBytes2UInt32(unsigned char *bytes)
00105 {
00106 unsigned int i;
00107 memcpy(&i, bytes, sizeof(unsigned int));
00108 return(i);
00109 }
00110
00111 float convertBytes2Float(unsigned char *bytes)
00112 {
00113 float f;
00114 memcpy(&f, bytes, sizeof(float));
00115 return(f);
00116 }
00117
00118
00119
00120 void convertInt8(char i, unsigned char *bytes)
00121 {
00122 memcpy(bytes, &i, sizeof(char));
00123 }
00124
00125 void convertUInt8(unsigned char i, unsigned char *bytes)
00126 {
00127 memcpy(bytes, &i, sizeof(unsigned char));
00128 }
00129
00130 void convertInt16(short i, unsigned char *bytes)
00131 {
00132 memcpy(bytes, &i, sizeof(short));
00133 }
00134
00135 void convertUInt16(unsigned short i, unsigned char *bytes)
00136 {
00137 memcpy(bytes, &i, sizeof(unsigned short));
00138 }
00139
00140 void convertInt32(int i, unsigned char *bytes)
00141 {
00142 memcpy(bytes, &i, sizeof(int));
00143 }
00144
00145 void convertUInt32(unsigned int i, unsigned char *bytes)
00146 {
00147 memcpy(bytes, &i, sizeof(unsigned int));
00148 }
00149
00150 void convertFloat(float f, unsigned char *bytes)
00151 {
00152 memcpy(bytes, &f, sizeof(float));
00153 }