delorie.com/archives/browse.cgi | search |
From: | Soenke_Ufen AT kruemel DOT org (Soenke Ufen) |
Newsgroups: | comp.os.msdos.djgpp |
Subject: | Re: Looking at the individual bits of a float. |
Date: | Thu, 9 Nov 2000 12:10:00 CET |
Organization: | Krmel Boks! |
Lines: | 34 |
Sender: | Soenke_Ufen AT kboks DOT kruemel DOT org |
Message-ID: | <MSGID_2=3A240=2F2188.47=40fidonet_fa4456fc@fidonet.org> |
References: | <6fqO5.60817$mv2 DOT 276178 AT news2-win DOT server DOT ntlworld DOT com> |
NNTP-Posting-Host: | pd4b9de86.dip.t-dialin.net (212.185.222.134) |
Mime-Version: | 1.0 |
X-Trace: | fu-berlin.de 973769414 1660173 212.185.222.134 (16 [23622]) |
User-Agent: | VSoup v1.2.9.48Beta [OS/2] |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
Hi Graham, g>I was wondering if anyone has any fast ways of looking at the g>individual bits and bytes of a float with or without (preferably) g>destroying the float in question. #include "pls_excuse_wrong_NG.h" #include <stdio.h> #include <limits.h> /* CHAR_BIT */ int main() { float x; char *b; int i, j; scanf("%f", &x); b = (char *) &x; for (i = 0; i < sizeof(float); i++) { for (j = CHAR_BIT - 1; j >= 0; j--) { if (b[i] & (1 << j)) printf("1"); else printf("0"); } } printf("\n"); }/* Optimization depends on implementation ;-) */ -- Bye, Sönke.
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |