fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. void binary_maska (int x){
  5. int maska = 1;
  6. int i;
  7. int b[32];
  8. for(i=0;i<32;i++){
  9. if ((maska&x)>0){
  10. b[i]=1;
  11. }else{
  12. b[i]=0;
  13. }
  14. maska=maska<<1;
  15. }
  16. for(i=31;i>=0;i--){
  17. printf("%d",b[i]);
  18. }
  19. }
  20. void binary_maska1 (float x){
  21. int i,fint;
  22. int maska = 1;
  23. int b[32];
  24. fint = *(int *)&x;
  25. for(i=0;i<32;i++){
  26. if ((maska&fint)>0){
  27. b[i]=1;
  28. }else{
  29. b[i]=0;
  30. }
  31. maska=maska<<1;
  32. }
  33. for(i=31;i>=0;i--){
  34. printf("%d",b[i]);
  35. }
  36. }
  37. void binary_maska2 (char x){
  38. int xforwrite=(int)x;
  39. int maska = 1;
  40. int i;
  41. int b[8];
  42. for (i=0;i<8;i++){
  43. if ((maska&xforwrite)>0){
  44. b[i]=1;
  45. }else{
  46. b[i]=0;
  47. }
  48. maska=maska<<1;
  49. }
  50. for (i=7;i>=0;i--){
  51. printf("%d",b[i]);
  52. }
  53. }
  54. int main(){
  55. printf("Enter the char:");
  56. char char1;
  57. scanf("%c",&char1);
  58. printf("Thats how char saves in PC memory:");
  59. binary_maska2(char1);
  60. printf("\n");
  61. printf("Enter the int:");
  62. int ch;
  63. scanf("%d",&ch);
  64. printf("Thats how int saves in PC memory:");
  65. binary_maska(ch);
  66. printf("\n");
  67. printf("Enter the float:");
  68. float ch1;
  69. scanf("%f",&ch1);
  70. printf("Thats how float saves in PC memory:");
  71. binary_maska1(ch1);
  72. printf("\n");
  73. return 0;
  74.  
  75. }
  76.  
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
Enter the char:Thats how char saves in PC memory:00000000
Enter the int:Thats how int saves in PC memory:00000000000000000000000000000000
Enter the float:Thats how float saves in PC memory:00000000000000000000000000000000