隨筆-295  評論-26  文章-1  trackbacks-0

          #include <iostream.h>
          #include <string>
          char* strToBinary(int x);
          char* strToHex(int i);
          char* transToGKB(char *t);

          int main ()

          {
          char *p=strToBinary(233);
          //cout<<p;

          //cout<<strToHex(233);
          cout<<transToGKB("商");
          return 0;
          }
          char* transToGKB(char *t){
          ?int res=0;
          ?? int intlen;
          ?? intlen=strlen(t);
          ?? if(intlen>1){
          ??? char *result=new char[5];
          ?? int i=0;
          ?if(0>t[0]){
          ??? res=256+t[0];
          ? }
          ?char *p1=strToHex(res);
          ?if(0>t[1]){
          ??res=256+t[1];
          ?}
          ?char *p2=strToHex(res);
          ?result=p1;
          ?result[2]=p2[0];
          ?result[3]=p2[1];?
          ?result[4]='\0';?
          ?return result;
          ?}
          ?? else{
          ??? //if(t[0]>64)
          ??? char * p=new char[3];
          ??? p=strToHex(t[0]);
          ??? p[2]='\0';
          ??? return? p;
          ?? }

          }

          ?

          //數字轉為二進制(255以內的正數)
          char* strToBinary(int i){
          ?char *result=new?? char[9];
          ?int n=1;
          ?int m;
          ?int c=0;
          ?int j=8;
          ?for(c=0;c<8;c++){
          ??m=i%2;
          ??j=j-1;
          ??i=n=i/2;
          ??if(n>=0){
          ???if (m>0){
          ????result[j]='1';
          ???}else
          ???{
          ????result[j]='0';
          ???}?
          ??}
          ??
          ?}
          ?result[8]='\0';
          ?
          //?cout<<result;
          ?return result;
          }
          //數字轉為十六進制(255以內的正數)
          char* strToHex(int i){
          ?char *result=new?? char[3];
          ?int n=1;
          ?int m;
          ?int c=0;
          ?int j=2;
          ?for(c=0;c<2;c++){
          ??m=i%16;
          ??j=j-1;
          ??i=n=i/16;
          ??if(n>=0){
          ???if (m>0){
          ????if (m==1){
          ????????????????? result[j]='1';
          ????}
          ????else if (m==2){
          ?????result[j]='2';
          ????}
          ????else if (m==3){
          ?????result[j]='3';
          ????}
          ????else if (m==4){
          ?????result[j]='4';
          ????}
          ????else if (m==5){
          ?????result[j]='5';
          ????}
          ????else if (m==6){
          ?????result[j]='6';
          ????}
          ????else if (m==7){
          ?????result[j]='7';
          ????}
          ????else if (m==8){
          ?????result[j]='8';
          ????}
          ????else if (m==9){
          ?????result[j]='9';
          ????}
          ????else if (m==10){
          ?????result[j]='A';
          ????}
          ????else if (m==11){
          ?????result[j]='B';
          ????}
          ????else if (m==12){
          ?????result[j]='C';
          ????}
          ????else if (m==13){
          ?????result[j]='D';
          ????}
          ????else if (m==14){
          ?????result[j]='E';
          ????}
          ????else if (m==15){
          ?????result[j]='F';
          ????}
          ???}else
          ???{
          ????result[j]='0';
          ???}?
          ??}
          ?}
          ?result[2]='\0';
          ?return result;
          }



          大盤預測 國富論
          posted on 2009-03-19 16:37 華夢行 閱讀(189) 評論(0)  編輯  收藏 所屬分類: C
          主站蜘蛛池模板: 黄骅市| 龙口市| 景泰县| 沙雅县| 海淀区| 香格里拉县| 饶阳县| 阿坝县| 甘孜| 姚安县| 珲春市| 什邡市| 拜泉县| 台东县| 寿阳县| 水城县| 德保县| 兴国县| 马鞍山市| 博爱县| 阳城县| 阜康市| 东源县| 铜山县| 高雄市| 游戏| 虞城县| 天津市| 沈丘县| 房产| 友谊县| 石阡县| 邮箱| 鹤岗市| 古丈县| 广宗县| 奈曼旗| 怀宁县| 灌云县| 驻马店市| 普格县|