Exemple #1
0
long _convert(int x)//递归进行二进制转换 
{
	if (x/10==0){
		return x;
	}	
	else{
		return _convert(x/10)*2+x%10;
	}
}
Exemple #2
0
int main()
{
	long bin;
	
	printf ("请输入二进制数:");
	scanf ("%d", &bin);
	
	printf ("对应的十进制数是:%ld\n", _convert(bin)); 
	
	system ("pause");
	return 0;	
}
Exemple #3
0
int main()
{
      int num, bit;
      
      printf ("请输入要转换的进制和待转换的十进制数(进制,十进制数):\n");
      scanf ("%d,%d", &bit, &num);
      
      printf("转换后%d进制数是", bit);
      _convert(num, bit);//调用函数转换并打印 

      system("pause");
      return 0;
}
void NxNSceneGraph::_addToGrid(ICollider* cdr)
{
    assert(cdr);
    _GridCell min = _hash( cdr->bounds().x(), cdr->bounds().y() );
    _GridCell max = _hash( cdr->bounds().x() + cdr->bounds().width(),
                           cdr->bounds().y() + cdr->bounds().height() );

    if (min.x == max.x && min.y == max.y)
    {
        int index = _convert(min);
        d_table[index].push(cdr);
    }

}
void TrimmedSurfaceConverter::_fetch_task() {
  bool something_to_do = true;

  while (something_to_do) {
    // try to get a task
    boost::mutex::scoped_lock lck(_impl->source_access);

    if (_impl->next != _impl->source->end()) {
      TrimmedNurbsSurface const& task = *(_impl->next);
      ++(_impl->next);
      _convert(task);

    } else {
      something_to_do = false;
    }
  }

}
Exemple #6
0
void convert(int ibeg, int iend,char in[], char out[]){
uinteger _Length;
integer BigEndian=0;
static ofstream fbout;
static int16u Record[100000];
int16u pData[2][24][1536];
  enum open_mode{binary=0x80};
  if(ibeg==0){
    fbout.open(out,ios::out|binary|ios::app);
      if(fbout){
       cout <<"cdaq-I-Open O file "<<out<<endl;
      }
      else {
        cerr <<"cdaq=F-CouldNotOPenFileO "<<out<<endl;
        exit(1);
      }




       integer b64=0;
       if(sizeof(ulong)>sizeof(uinteger))b64=1;
       uinteger test1,test2;
       test1=1;
       test1+=2<<8;
       test1+=4<<16;
       test1+=8<<24;
       unsigned char *pt= (unsigned char*)&test1;
       test2=pt[0];
       test2+=pt[1]<<8;
       test2+=pt[2]<<16;
       test2+=pt[3]<<24;
       integer lend = test1==test2;
       if(lend)cout <<"AMSTrIdSoftI-I-Identified as LittleEndian";
       else {
         cout <<"AMSTrIdSoftI-I-Identified as BigEndian";
         BigEndian=1;
       }
       if(b64)cout <<" 64 bit machine."<<endl;
       else cout <<" 32 bit machine."<<endl;
      






  }
    
    ifstream fbin;
    fbin.open(in,ios::in|binary);
    int fevt=1;
    static int gevt=0;
    static int terr=0;
    int tevt=0;
    char name[80];
    strncpy(name,in+strlen(in)-6,6);
    int run =atoi(name);    
    run=run/100;
    cout <<"run "<<run<<endl;
    long id, size, flags;
    time_t time;
    int suc=UnixFilestat(in, &id, &size,&flags, &time);
    cout <<ctime(&time);
    int ie;
      if(fbin){
       cout <<"cdaq-I-Open I file "<<in<<endl;
      }
      else {
        cerr <<"cdaq=F-CouldNotOPenFileI "<<in<<endl;
        exit(1);
      }
       int ncnt=0;
       int eventok=0;
       do {
       int16u tdrno=-1;
       int16u evto=-1;
       int l16ptr=0;
       int tlength,ntdr,len,tdrn,ch1,ch2,elem;
       ie=fscanf(fbin,"%x",&tlength);
       l16ptr++;
       ie=fscanf(fbin,"%x",&ntdr);
       l16ptr++;
                cout << " tlength "<<tlength <<endl;
       //         cout << " ntdr "<<ntdr <<endl;
       if(ie!=EOF && ntdr>0){
       }
       else{
         
         break;
       }
       do{
       ie=fscanf(fbin,"%x",&tdrn);
       ie=fscanf(fbin,"%x",&len);
       ie=fscanf(fbin,"%x",&evt);
       cdr[nrecords++]=tdrn;
                cout << " ntdr "<<ntdr <<" "<<tdrn<<" "<<len<<" "<<evt<<endl;
         assert(len-4 <= 1536);
         for(int i=0;i<len-4;i++){
          ie=fscanf(fbin,"%x",&elem);
          pData[tdrn][i]=elem;
         }                
          ie=fscanf(fbin,"%x",&ch1);
          ie=fscanf(fbin,"%x",&ch2);
          l16ptr+=len+1;         
       }while (l16ptr<tlength);
       if(tdrn == 23){
         if(nrecords != 24 ){
           cerr <<" cdaq-E-EventError-"<<nrecords<<" "<<endl;
         }
           for(int ll=0;ll<nrecords;ll++){
             if(cdr[ll]!=ll)cout <<"cdaq-OrderError"<<ll<<" "<<cdr[ll]<<endl;
           }
          }
          ncnt=0;



       if(eventok){
         // read whole event; try to write it
         fevt=0;
         
         Record[1]=0x0;
         Record[2]=9;
         Record[3]=0x200;
         Record[4]=run&65535;
         Record[5]=(run>>16)&65535;
         Record[6]=0;
         Record[7]=evt&65535;
         Record[8]=(evt>>16)&65535;
         Record[9]=time&65535;
         Record[10]=(time>>16)&65535;
         Record[11]=0;
         _Length=Record[2]+1+1;
         int frp=12;
         // first crate
         for(int icrt=0;icrt<2;icrt++){
          Record[frp]=(32)*(640+1)+32*(384+1)+1;
          _Length+=Record[frp]+1;
          frp++;
          if(icrt==0)Record[frp]= 2<<6 | 11 <<9;    // 2 Crate 32; 5 for 72
          else Record[frp]= 5<<6 | 11 <<9; 
          frp++;
          for (int k=0;k<16;k++){
           for(int j=0;j<2;j++){
             // make address
             int16u conn, tdrs;
             if(k%2 ==0 ){
               if(j==0)conn=0;
               else conn=1; 
             }             
             else{
               if(j==0)conn=2;
               else conn=3; 
             }
             tdrs=k/2;
             //             if(icrt==0 && conn==2 && tdrs==7)continue;
             int16u addr=(conn<<10) | (tdrs <<12);
             Record[frp]=addr;
             frp++;
             int lj;
             if(j==0)lj=2;
             else lj=0;
             for(int l=0;l<320;l++){
              Record[frp]=pData[icrt][k][lj*384+l];
              Record[frp]=Record[frp] | (1<<15);
              frp++;     
             }
             if(j==0)lj=3;
             else lj=1;
             for( l=0;l<320;l++){
              Record[frp]=pData[icrt][k][lj*384+l];
              Record[frp]=Record[frp] | (1<<15);
              frp++;     
             }
           }
         }
         for(k=16;k<24;k++){
           for(int j=0;j<4;j++){
             // make address
             int16u conn, tdrk;
             if(k%2 ==0){
              if(j<2)conn=j+2;
              else conn=j-2;
             }
             else {
              if(j<2)conn=j+2;
              else conn=j-2;
               conn+= 4;
             }
             tdrk=(k-16)/2;
             //swap 3.2 <-> 3.0 for 32
             if(icrt==0 && tdrk == 2){
              if(conn == 0)conn=3;
              else if (conn==3)conn=0;  
             }
             int16u addr=(10<<6) |( conn<<10) | (tdrk <<13);
               
             Record[frp]=addr;
             frp++;
             for(int l=0;l<384;l++){
              Record[frp]=pData[icrt][k][j*384+l];
              Record[frp]=Record[frp] | (1<<15);
              frp++;     
              
             }
           }
         }
         }
         //make length
          Record[0]=_Length%65536;
          Record[1]=Record[1] | (_Length/65536);
         int tl=_Length+1;
         //         cout <<" tl "<<tl<<endl;
              //  Dump every 1000 event
         //                           if(evt%1000 == 0){
         //                             for(int itl=0;itl<tl;itl++){
         //                               cout <<itl <<" "<<Record[itl]<<endl;
         //                             }
         //                           }
         _convert(Record,tl,BigEndian);
         // skip first event for safety
         //cout <<" write " <<tevt << endl;
         if(tevt!=0)fbout.write((unsigned char*)Record,tl*sizeof(Record[0]));  
         tevt++;
       }



        }  
       if(fbin.good()&& !fbin.eof() ){
       }
       else{
         
         break;
       }
       fbin.read((unsigned char*)&tlength,sizeof(tlength));
       _convertl(tlength,BigEndian);
       //       cout << "tlength "<<tlength<<endl;
       tlength++;
       if(tlength != 3084 ){
         cerr<<"cdaqn-S-Bad Total Length "<<tlength<<endl;
         int nskp=0;
         while(tlength !=3084 || !fbin.eof()){
         fbin.read((unsigned char*)&tlength,sizeof(tlength));
         _convertl(tlength,BigEndian);
         tlength++;
         nskp++;
         }
         cerr<<"cdaqn-S-"<<nskp<<" words skipped"<<endl;
       }
       l16ptr++;
       fbin.read((unsigned char*)&ntdr,sizeof(ntdr));
       _convertl(ntdr,BigEndian);
       ncrt=0;
       if(ntdr & (1<<12))ncrt=1;
       ntdr=ntdr & ~(1<<12); 
       ncnt++;
       l16ptr++;
       //cout << " tlength "<<tlength <<endl;
       //cout << " ntdr "<<ntdr <<" "<<ncrt<<endl;
       if(fbin.good()&& !fbin.eof() ){
       }
       else{
         
         break;
       }
       do{
       tdrno=tdrn;       
       fbin.read((unsigned char*)&tdrn,sizeof(tdrn));
       fbin.read((unsigned char*)&len,sizeof(tdrn));
       fbin.read((unsigned char*)&evt,sizeof(tdrn));
       _convertl(tdrn,BigEndian);
       _convertl(len,BigEndian);
       _convertl(evt,BigEndian);
       //cout << " ntdr "<<ntdr <<" "<<tdrn<<" "<<len<<" "<<evt<<" "<<ncrt<<" "<<ncnt<<endl;
       if(len-4 != 1536){
         cerr <<" Cdaq-S-wrong length event # "<<evt<<" "<<len-4<<endl;
         // Try to skip to another event
       }
                assert(len-4 <= 1536);
          fbin.read((unsigned char*)pData[ncrt][tdrn],sizeof(pData[0][0][0])*(len-4));
          _convert(pData[ncrt][tdrn],len-4,BigEndian);
          fbin.read((unsigned char*)&ch1,sizeof(ch1));
          fbin.read((unsigned char*)&ch2,sizeof(ch2));
          l16ptr+=len+1;         
       }while (l16ptr<tlength);
      }while (fbin.good() && !fbin.eof());