levur

main.cpp

Aug 29th, 2012
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include "ip.h"
  4. #include "octet.h"
  5.  
  6. using namespace std;
  7.  
  8.  
  9. string ToBits(int oct);
  10.  
  11.  
  12. int main()
  13. {
  14. Octet oct1, oct2, oct3, oct4;
  15. int byte1 ,byte2 ,byte3 ,byte4;
  16.  
  17. byte1 = byte2 = byte3 = byte4 = 0;
  18.  
  19. cout << "Saisir le 1er octet de votre adresse :" << endl;
  20. cin >> byte1;
  21. oct1.setOctet(byte1);
  22. cout << "Saisir le 2em octet de votre adresse :" << endl;
  23. cin >> byte2;
  24. oct2.setOctet(byte2);
  25. cout << "Saisir le 3em octet de votre adresse :" << endl;
  26. cin >> byte3;
  27. oct3.setOctet(byte3);
  28. cout << "Saisir le 4em octet de votre adresse :" << endl;
  29. cin >> byte4;
  30. oct4.setOctet(byte4);
  31.  
  32. IP ip(oct1, oct2, oct3, oct4);
  33.  
  34. cout << ip.ToBits() << endl;
  35.  
  36. cout << ToBits(ip.getOct1()) << endl;
  37. cout << ToBits(ip.getOct2()) << endl;
  38. cout << ToBits(ip.getOct3()) << endl;
  39. cout << ToBits(ip.getOct4()) << endl;
  40.  
  41. system("Pause");
  42. }
  43.  
  44.  
  45.  
  46. string ToBits(int oct)
  47. {
  48. string rep = "";
  49. int comp = 128;
  50.  
  51. for(int i =0; i<8; i++)
  52. {
  53. if(oct < comp)
  54. { rep = rep + "0";
  55. }
  56. else
  57. { rep = rep + "1";
  58. oct = oct - comp;
  59. }
  60.  
  61. comp = comp/2;
  62. }
  63. return rep;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment