Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include "IspisBroja.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. IspisBroja::IspisBroja() {
  7. this->fbroj = 0;
  8. }
  9.  
  10. void IspisBroja::postaviFloat(float broj) {
  11. this->fbroj = broj;
  12. }
  13.  
  14. void IspisBroja::ispisiBinarnoFloat() {
  15. unsigned char *p = (unsigned char*)&fbroj;
  16.  
  17. cout << endl;
  18. for (int i = 3; i >= 0; i--) {
  19. for (int j = 7; j >= 0; j--) {
  20. (p[i] & (1 << j)) ? cout << "1" : cout << "0";
  21. }
  22. }
  23. cout << endl;
  24. }
  25.  
  26. void IspisBroja::toBinary() {
  27. int fl = *(int*)&fbroj;
  28. cout << *(int*)&fbroj << endl;
  29. for (int i = sizeof(float) * 8 - 1; i >= 0; i--) {
  30. cout << (((1 << i) & fl) != 0 ? 1 : 0);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement