00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "types.h"
00024
00025 #include <math.h>
00026
00027 #include <iostream>
00028 #include <iomanip>
00029 using namespace std;
00030
00031 unsigned int char2num(char c)
00032 {
00033 int res=(int)c;
00034 if(res<0) res+=256;
00035 return res;
00036 }
00037
00038 char num2char(unsigned int i)
00039 {
00040 if(i>=128)
00041 return (char)(i-256);
00042 else
00043 return (char)i;
00044 }
00045
00046 dword byte2dword(byte array[])
00047 {
00048 dword result=0;
00049 for(int i=0;i<4;i++)
00050 {
00051 result=(result<<8);
00052 result+=array[i];
00053 }
00054
00055 return result;
00056 }
00057
00058 byte* dword2byte(dword var)
00059 {
00060 byte* result=new byte[4];
00061 for(int i=3;i>=0;i--)
00062 {
00063 result[i]=var & 0x000000FF;
00064 var=(var>>8);
00065 }
00066 return result;
00067 }
00068
00069 word byte2word(byte array[])
00070 {
00071 word result=0;
00072 for(int i=0;i<2;i++)
00073 {
00074 result=(result<<8);
00075 result+=array[i];
00076 }
00077
00078 return result;
00079 }
00080
00081 byte* word2byte(word var)
00082 {
00083 byte* result=new byte[2];
00084 for(int i=1;i>=0;i--)
00085 {
00086 result[i]=var & 0x00FF;
00087 var=(var>>8);
00088 }
00089 return result;
00090 }