Skip to content
Snippets Groups Projects

Binary representation of floats in c

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by John Madden

    Simple main.c file to investigate the binary representation of floating point values. The value 0.0 as a float has the binary representation of 0b0 or all zeros. Thus, this allows the value to be compared using ==.

    Edited
    main.c 250 B
    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
      printf("Hello, World!\n");
    
      double double_zero = 0.0;
      float float_zero = 0.0f;
      int int_zero = 0;
      
      double double_one = 1.0;
      float float_one = 1.0f;
      int int_one = 1;
    
      return 0;
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment