asmodeus94

dziesNaBinI...

Sep 26th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<ctime>
  4. #include<cstdlib>
  5.  
  6. using namespace std;
  7. string przekrec(string co){
  8.     string gotowe="";
  9.     int y1=7;
  10.     for(int y=7;y>=0;y--){
  11.         gotowe+=co[y];
  12.     }
  13.     return gotowe;
  14. }
  15. string zwrocZera(string co,int ile){
  16.     string no;
  17.     for(int x=0;x<8-ile;x++){
  18.         co+="0";
  19.     }
  20.     return przekrec(co);
  21. }
  22. string u2(int a){
  23.     int chw=a,bierz,dl,ktoryRaz=0;
  24.     string u22,kol,kol1;
  25.     do{
  26.         bierz=chw;
  27.         kol="";
  28.         u22="";
  29.         if(ktoryRaz==1){
  30.             bierz=256-chw;
  31.         }
  32.         do{
  33.             if(bierz%2==1) u22+='1'; else u22+='0';            
  34.             bierz/=2;
  35.         }while(bierz>=1);
  36.         dl=u22.length();
  37.         u22=zwrocZera(u22,dl);
  38.         kol+=u22;
  39.         if(ktoryRaz==0) kol1+="binarnie: "+kol+"\n";
  40.         else kol1+="u2: "+kol;
  41.         ktoryRaz++;
  42.     }while(ktoryRaz!=2);
  43.     return kol1;
  44. }
  45. int main(){
  46.     int podL;
  47.     cout<<"Podaj liczbe: ";cin>>podL;cout<<u2(podL)<<"\n";
  48.     system("pause");
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment