Advertisement
ItsMeLucifer

DEC->BIN+HEX C++

Apr 23rd, 2019
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int l=0,licznik=-1,l2,licznik2=-1;
  10.     cout<<"Podaj liczbe dziesietna, ktora chcesz przeksztalcic na system dwojkowy oraz szesnastkowy"<<endl;
  11.     cin>>l;
  12.     l2=l;
  13.     int tab[30];
  14.     for(int i=0;l>0;i++){
  15.         if(l%2==0){
  16.             tab[i]=0;
  17.         }else if(l%2==1){
  18.             tab[i]=1;
  19.         }
  20.         l/=2;
  21.         licznik++;
  22.     }
  23.     cout<<"Binarnie: ";
  24.     for(int j=licznik;j>=0;j--){
  25.         cout<<tab[j];
  26.     }
  27.     cout<<endl;
  28.     //!Do poprawki nizej
  29.     /*
  30.     string tab2[30];
  31.     int liczba;
  32.     for(int i=0;l2>0;i++){
  33.         if(l2%16<10){
  34.             liczba=l2%16;
  35.             tab2[i]= liczba;
  36.         }else if(l2%16==10){
  37.             tab2[i]="A";
  38.         }else if(l2%16==11){
  39.             tab2[i]="B";
  40.         }else if(l2%16==12){
  41.             tab2[i]="C";
  42.         }else if(l2%16==13){
  43.             tab2[i]="D";
  44.         }else if(l2%16==14){
  45.             tab2[i]="E";
  46.         }else if(l2%16==15){
  47.             tab2[i]="F";
  48.         }
  49.         l2/=16;
  50.         if(l2!=0)licznik2++;
  51.     }
  52.     cout<<"Szesnastkowo: ";
  53.     for(int j=licznik2;j>=0;j--){
  54.         cout<<tab2[j];
  55.     }
  56.     */
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement