Advertisement
Guest User

Untitled

a guest
Sep 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. char toh (int u) {
  6. char a='A',b='B',c='C',d='D',e='E',f='F';
  7. if(u==10) return a;
  8. if (u==11) return b;
  9. if (u==12) return c;
  10. if (u==13) return d;
  11. if (u==13) return e;
  12. if (u==14) return f;
  13.  
  14. }
  15.  
  16. int main()
  17. {
  18. int x=0,rdz=0,licznik=1;
  19. int s01=0,s02=0,s03=0,s04=0,s05=0,s06=0,s07=0,s08=0,s09=0,s10=0,s11=0,s12=0,s13=0,s14=0;
  20. do{
  21. cout <<"Podaj liczbe (0<=x<10000): ";
  22. cin >>x;
  23. }while (x<0 or x>=10000);
  24. do{
  25. rdz=x%2;
  26. if (licznik==1) s01=rdz;if (licznik==2) s02=rdz;if (licznik==3) s03=rdz;
  27. if (licznik==4) s04=rdz;if (licznik==5) s05=rdz;if (licznik==6) s06=rdz;
  28. if (licznik==7) s07=rdz;if (licznik==8) s08=rdz;if (licznik==9) s09=rdz;
  29. if (licznik==10) s10=rdz;if (licznik==11) s11=rdz;if (licznik==12) s12=rdz;
  30. if (licznik==13) s13=rdz;if (licznik==14) s14=rdz;
  31. if (rdz==0) x=x/2;
  32. if(rdz!=0){
  33. x=x-1;
  34. x=x/2;
  35. }
  36. licznik++;
  37. }while (x!=0);
  38. cout << "/n Binarne wynosi: " << s14 << s13 << s12 << s11 << s10 << s09 << s08 << s07 << s06 << s05 << s04 << s03 << s02 << s01;
  39. //osemkowy
  40. int o01=0,o02=0,o03=0,o04=0,o05=0;
  41. o01 = (s01*1)+(s02*2)+(s03*4);
  42. o02 = (s04*1)+(s05*2)+(s06*4);
  43. o03 = (s07*1)+(s08*2)+(s09*4);
  44. o04 = (s10*1)+(s11*2)+(s12*4);
  45. o05 = (s13*1)+(s14*2);
  46. cout << "\osemkowo wynosi: " << o05 << o04 << o03 << o02 << o01;
  47. //szesnastkowy
  48. int v01=0, v02=0, v03=0, v04=0;
  49. char cv01,cv02,cv03,cv04;
  50. v01=(s01*1)*(s02*2)*(s03*4)*(s04*8);
  51. v02=(s05*1)*(s06*2)*(s07*4)*(s08*8);
  52. v03=(s09*1)*(s10*2)*(s11*4)*(s12*8);
  53. v04=(s13*1)*(s14*2);
  54. cout<<"\n Szesnastkowo wynik wynosi: "<<v04<<v03<<v02<<v01;
  55. if(v01>9) cv01=toh(v01);
  56. if(v02>9) cv02=toh(v02);
  57. if(v03>9) cv03=toh(v03);
  58. if(v04>9) cv04=toh(v04);
  59. cout<<"\n Szesnastkowo wynik wynosi: ";
  60.  
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement