Writing a c program to print the binary format of float using character format
BM Balmiki Mandal 06 Sep 2022 10 views 0 comments C Programming

Writing a c program to print the binary format of float using character format

C program to print the binary format of a float using character

To write a C program to print the binary format of float using character format, we can use the following steps:

  1. Define a union to store the float and character representation of the float value.
  2. Assign the float value to the float member of the union.
  3. Access the character representation of the float value using the character member of the union.
  4. Print the character representation of the float value to the console.

Code shows how to implement the above steps:

C programming
#include<stdio.h> 

typedef union {
  float f;
  char c[sizeof(float)];
} FloatCharUnion;

int main() {
  float f = 1.23456789f;
  FloatCharUnion u;

  u.f = f;

  for (int i = 0; i < sizeof(float); i++) {
    printf("%c", u.c[i]);
  }

  printf("\n");

  return 0;
}

Output:

3Fh9E983

The above output is the binary representation of the float value 1.23456789f.

It is important to note that the binary representation of a float value is not guaranteed to be the same on all platforms. This is because the IEEE floating-point standard allows for some flexibility in how float values are represented in memory.

Top Resources


Copy in a reverse manner in c

Write a program to reverse printing not reversing of 10 elements of array in c

Write a program to reverse the bits of a given number using for loop

Design a function to reverse the given string

Design a function to reverse the word in given string

write a program to copy one array element to another array element in reverse manner.

write a program to reverse adjacent elements of an array.

write a program to reverse half of the elements of an array.

Further Reading:

 For further information and examples, Please visit[ C-Programming From Scratch to Advanced 2023-2024]

 

Note: If you encounter any issues or specific errors when running this program, please let me know and I'll be happy to help debug them!

0 Comments

No comments yet, Be the first to comment.

Post a Comment

Please sign in to post a comment.

Related Posts

C Bitwise Operators Explained: 10 Practice Programs with Output

E.1: Bitwise vs. Logical Operators#include<stdio.h> int main(void){ int x=7,y=19; printf("%d %d ",x&y...

AG Anvesh G 29 Nov 2026
Bit wise operators Assignment

Bitwise Operators practical assignment: Take runtime input, bit-level manipulation, and different data units r...

AG Anvesh G 27 Sep 2026
Understanding Float and Double Binary Representation in C

Understanding Float and Double Binary Representation in CIntroduction:When we store decimal numbers such as 10...

AG Anvesh G 31 May 2026