Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include "ip.h"
- #include "octet.h"
- using namespace std;
- string ToBits(int oct);
- int main()
- {
- Octet oct1, oct2, oct3, oct4;
- int byte1 ,byte2 ,byte3 ,byte4;
- byte1 = byte2 = byte3 = byte4 = 0;
- cout << "Saisir le 1er octet de votre adresse :" << endl;
- cin >> byte1;
- oct1.setOctet(byte1);
- cout << "Saisir le 2em octet de votre adresse :" << endl;
- cin >> byte2;
- oct2.setOctet(byte2);
- cout << "Saisir le 3em octet de votre adresse :" << endl;
- cin >> byte3;
- oct3.setOctet(byte3);
- cout << "Saisir le 4em octet de votre adresse :" << endl;
- cin >> byte4;
- oct4.setOctet(byte4);
- IP ip(oct1, oct2, oct3, oct4);
- cout << ip.ToBits() << endl;
- cout << ToBits(ip.getOct1()) << endl;
- cout << ToBits(ip.getOct2()) << endl;
- cout << ToBits(ip.getOct3()) << endl;
- cout << ToBits(ip.getOct4()) << endl;
- system("Pause");
- }
- string ToBits(int oct)
- {
- string rep = "";
- int comp = 128;
- for(int i =0; i<8; i++)
- {
- if(oct < comp)
- { rep = rep + "0";
- }
- else
- { rep = rep + "1";
- oct = oct - comp;
- }
- comp = comp/2;
- }
- return rep;
- }
Advertisement
Add Comment
Please, Sign In to add comment