levur

octet.cpp

Aug 29th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include "octet.h"
  2. #include <string>
  3.  
  4.  
  5. Octet::Octet(int a)
  6. {
  7. numerique = a;
  8. //ctor
  9. }
  10. Octet::Octet()
  11. {
  12. //ctor
  13. }
  14.  
  15. Octet::~Octet()
  16. {
  17. //dtor
  18. }
  19.  
  20. void Octet::setOctet(int a)
  21. {
  22. numerique = a;
  23. }
  24.  
  25. int Octet::getOctet()
  26. {
  27. return numerique;
  28. }
  29.  
  30. std::string Octet::ToBits()
  31. {
  32. std::string rep = "";
  33. int a = numerique; // ne recupère pas la bonne valeurs :(
  34. int comp = 128;
  35.  
  36. for(int i =0; i<8; i++)
  37. {
  38. if(a < comp)
  39. { rep = rep + "0";
  40. }
  41. else
  42. { rep = rep + "1";
  43. a = a - comp;
  44. }
  45.  
  46. comp = comp/2;
  47. }
  48. return rep;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment