473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

representations

I'm trying to think of what one-third looks like when represented by two's
complement. What is its length? I'm not schur. It would be a DWORD in
assembly. In c, it would be (I think:)
float r = (float)(one third)
My syntax is somewhat wanting.

I think the question can be stated unambiguously if I ask what one-third
looks like with two's complement representation and a length of 32 bits.
--
LS
Mar 26 '07 #1
24 1446

"Lane Straatman" <in*****@invalid.netha scritto nel messaggio
news:es******************************@comcast.com. ..
I'm trying to think of what one-third looks like when represented by two's
complement. What is its length? I'm not schur. It would be a DWORD in
assembly. In c, it would be (I think:)
float r = (float)(one third)
My syntax is somewhat wanting.

I think the question can be stated unambiguously if I ask what one-third
looks like with two's complement representation and a length of 32 bits.
Two's complement is a representation for signed integers.
What did you *really* mean?
Mar 26 '07 #2

"Army1987" <pl********@for.itwrote in message
news:eu**********@tdi.cu.mi.it...
>
"Lane Straatman" <in*****@invalid.netha scritto nel messaggio
news:es******************************@comcast.com. ..
>I'm trying to think of what one-third looks like when represented by
two's complement. What is its length? I'm not schur. It would be a
DWORD in assembly. In c, it would be (I think:)
float r = (float)(one third)
My syntax is somewhat wanting.

I think the question can be stated unambiguously if I ask what one-third
looks like with two's complement representation and a length of 32 bits.

Two's complement is a representation for signed integers.
What did you *really* mean?
I knew I was in trouble there. What possiblities does one have for
representing one-third as a float in C, in particular with 32 bits?
--
LS
Mar 26 '07 #3
Lane Straatman wrote:
"Army1987" <pl********@for.itwrote in message
news:eu**********@tdi.cu.mi.it...

"Lane Straatman" <in*****@invalid.netha scritto nel messaggio
news:es******************************@comcast.com. ..
I'm trying to think of what one-third looks like when represented by
two's complement. What is its length? I'm not schur. It would be a
DWORD in assembly. In c, it would be (I think:)
float r = (float)(one third)
My syntax is somewhat wanting.

I think the question can be stated unambiguously if I ask what one-third
looks like with two's complement representation and a length of 32 bits.
Two's complement is a representation for signed integers.
What did you *really* mean?
I knew I was in trouble there. What possiblities does one have for
representing one-third as a float in C, in particular with 32 bits?
Every possible bit pattern is a potential valid representation of the
best approximation to one-third, or even the exact representation of
it. There are practically no requirements on how a float is stored in
memory.

As Army1987 asked, what did you *really* mean?

Mar 26 '07 #4

"Lane Straatman" <in*****@invalid.netwrote in message
>
"Army1987" <pl********@for.itwrote in message
news:eu**********@tdi.cu.mi.it...
>>
"Lane Straatman" <in*****@invalid.netha scritto nel messaggio
news:es******************************@comcast.com ...
>>I'm trying to think of what one-third looks like when represented by
two's complement. What is its length? I'm not schur. It would be a
DWORD in assembly. In c, it would be (I think:)
float r = (float)(one third)
My syntax is somewhat wanting.

I think the question can be stated unambiguously if I ask what one-third
looks like with two's complement representation and a length of 32 bits.

Two's complement is a representation for signed integers.
What did you *really* mean?
I knew I was in trouble there. What possiblities does one have for
representing one-third as a float in C, in particular with 32 bits?
Do you know what sign, mantissa and exponent mean, in relation to floating
point numbers?

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Mar 26 '07 #5

"Harald van D?k" <tr*****@gmail.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
Lane Straatman wrote:
>"Army1987" <pl********@for.itwrote in message
news:eu**********@tdi.cu.mi.it...
>
"Lane Straatman" <in*****@invalid.netha scritto nel messaggio
news:es******************************@comcast.com. ..
I'm trying to think of what one-third looks like when represented by
two's complement. What is its length? I'm not schur. It would be a
DWORD in assembly. In c, it would be (I think:)
float r = (float)(one third)
My syntax is somewhat wanting.

I think the question can be stated unambiguously if I ask what
one-third
looks like with two's complement representation and a length of 32
bits.

Two's complement is a representation for signed integers.
What did you *really* mean?
I knew I was in trouble there. What possiblities does one have for
representing one-third as a float in C, in particular with 32 bits?

Every possible bit pattern is a potential valid representation of the
best approximation to one-third, or even the exact representation of
it. There are practically no requirements on how a float is stored in
memory.
That's what I thought. How is it usually represented?
--
Mar 26 '07 #6

"Malcolm McLean" <re*******@btinternet.comwrote in message
news:FN******************************@bt.com...
>
"Lane Straatman" <in*****@invalid.netwrote in message
>>
"Army1987" <pl********@for.itwrote in message
news:eu**********@tdi.cu.mi.it...
>>>
"Lane Straatman" <in*****@invalid.netha scritto nel messaggio
news:es******************************@comcast.co m...
I'm trying to think of what one-third looks like when represented by
two's complement. What is its length? I'm not schur. It would be a
DWORD in assembly. In c, it would be (I think:)
float r = (float)(one third)
My syntax is somewhat wanting.

I think the question can be stated unambiguously if I ask what
one-third looks like with [some reasonable representation] and a length
of 32 bits.

Two's complement is a representation for signed integers.
What did you *really* mean?
I knew I was in trouble there. What possiblities does one have for
representing one-third as a float in C, in particular with 32 bits?
Do you know what sign, mantissa and exponent mean, in relation to floating
point numbers?
There was a recent thread with Joe Wright and others that is probably as
much as I know about it. The sign will take a bit. The mantissa is the a
in the a**x. The exponent is the exponent, x.
--
Mar 26 '07 #7
On Mon, 26 Mar 2007 16:41:16 -0400, "Lane Straatman"
<in*****@invalid.netwrote:
>
"Harald van D?k" <tr*****@gmail.comwrote in message
news:11**********************@l77g2000hsb.googleg roups.com...
>Lane Straatman wrote:
>>"Army1987" <pl********@for.itwrote in message
news:eu**********@tdi.cu.mi.it...

"Lane Straatman" <in*****@invalid.netha scritto nel messaggio
news:es******************************@comcast.com ...
I'm trying to think of what one-third looks like when represented by
two's complement. What is its length? I'm not schur. It would be a
DWORD in assembly. In c, it would be (I think:)
float r = (float)(one third)
My syntax is somewhat wanting.

I think the question can be stated unambiguously if I ask what
one-third
looks like with two's complement representation and a length of 32
bits.

Two's complement is a representation for signed integers.
What did you *really* mean?
I knew I was in trouble there. What possiblities does one have for
representing one-third as a float in C, in particular with 32 bits?

Every possible bit pattern is a potential valid representation of the
best approximation to one-third, or even the exact representation of
it. There are practically no requirements on how a float is stored in
memory.
That's what I thought. How is it usually represented?
At the risk of spoiling all the fun, I suggest you Google for "IEEE
floating point", which should get you lots of information.

--
Al Balmer
Sun City, AZ
Mar 26 '07 #8
Lane Straatman wrote:
"Harald van D?k" <tr*****@gmail.comwrote in message
>Every possible bit pattern is a potential valid representation of the
best approximation to one-third, or even the exact representation of
it. There are practically no requirements on how a float is stored in
memory.
That's what I thought. How is it usually represented?
#include <stdio.h>
#include <string.h>
#include <float.h>

int main(void)
{
float fltvalue = 1. / 3.;
double dblvalue = 1. / 3.;
long double lngdblvalue = 1.L / 3.;

unsigned char fltchars[sizeof fltvalue], dblchars[sizeof dblvalue],
lngdblchars[sizeof lngdblvalue];
size_t i;

printf("Every implementation is free to choose its own\n"
"method for storing floating point values.\n"
"Here is how one implementation stores 1/3.\n");

memcpy(fltchars, &fltvalue, sizeof fltvalue);
printf("As float 1/3 = %.*g\nHex: ", FLT_DIG, fltvalue);
for (i = 0; i < sizeof fltvalue; i++)
printf("%u ", fltchars[i]);
printf("\n\n");
memcpy(dblchars, &dblvalue, sizeof dblvalue);
printf("As double 1/3 = %.*g\nHex: ", DBL_DIG, dblvalue);
for (i = 0; i < sizeof dblvalue; i++)
printf("%u ", dblchars[i]);
printf("\n\n");

memcpy(lngdblchars, &lngdblvalue, sizeof lngdblvalue);
printf("As long double 1/3 = %.*Lg\nHex: ", LDBL_DIG, lngdblvalue);
for (i = 0; i < sizeof lngdblvalue; i++)
printf("%u ", lngdblchars[i]);
printf("\n\n");

return 0;
}
Every implementation is free to choose its own
method for storing floating point values.
Here is how one implementation stores 1/3.
As float 1/3 = 0.333333
Hex: 171 170 170 62

As double 1/3 = 0.333333333333333
Hex: 85 85 85 85 85 85 213 63

As long double 1/3 = 0.333333333333333333
Hex: 171 170 170 170 170 170 170 170 253 63 0 0
Mar 26 '07 #9

"Lane Straatman" <in*****@invalid.netwrote in message
news:5K******************************@comcast.com. ..
>
"Army1987" <pl********@for.itwrote in message
news:eu**********@tdi.cu.mi.it...
>>
"Lane Straatman" <in*****@invalid.netha scritto nel messaggio
news:es******************************@comcast.com ...
>>I'm trying to think of what one-third looks like when represented by
two's complement. What is its length? I'm not schur. It would be a
DWORD in assembly. In c, it would be (I think:)
float r = (float)(one third)
My syntax is somewhat wanting.

I think the question can be stated unambiguously if I ask what one-third
looks like with two's complement representation and a length of 32 bits.

Two's complement is a representation for signed integers.
What did you *really* mean?
I knew I was in trouble there. What possiblities does one have for
representing one-third as a float in C, in particular with 32 bits?
00111110101010101010101010101011
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Aero Stability and Controls Computing
Mar 26 '07 #10

"Lane Straatman" <in*****@invalid.netwrote in message "Malcolm McLean"
<re*******@btinternet.comwrote in message
>Do you know what sign, mantissa and exponent mean, in relation to
floating point numbers?
There was a recent thread with Joe Wright and others that is probably as
much as I know about it. The sign will take a bit. The mantissa is the a
in the a**x. The exponent is the exponent, x.
Nearly right.
IEEE standard floating point number use something very similar to scientific
notation.
2000 is 2 * 10^3 in this notation.
By convention there is only one decimal digit before the point, so
2300 is 2.3 * 10^3
Numbers below one have negative exponents
0.023 = 2.3 * 10^-2 (mnemonic, count the zeroes, including the leading one)

2.3 itself is 2.3 * 10^0.

Floating point numbers are basically just the same, but in binary. Since the
leading most significant binary digit must always be one, most
representations including IEEE save a bit by omitting it. There is one
exception to this rule, zero, so zero is represented specially by all bits
zero. Since zero is 10^-inf, it makes sense to store exponents in a sign
magnitude encoding rather than twos complement, so that 0 is the lowest, 1
= -127 or whatever, and so on. The sign bit is self explanatory.
Finally there are a few special representations for infinity, not a number,
and what are called denormalised numbers, but you can ignore those for now.

By looking at the bit patterns in your compiler, you should be able to work
out how many bits are allocated to each section, and what the exponent
encoding is. Start with one and minus one to get the sign bit.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
Mar 26 '07 #11
"Lane Straatman" <in*****@invalid.netwrites:
I'm trying to think of what one-third looks like when represented by two's
complement. What is its length? I'm not schur. It would be a DWORD in
assembly. In c, it would be (I think:)
float r = (float)(one third)
float r = 1.0/3.0;
My syntax is somewhat wanting.

I think the question can be stated unambiguously if I ask what one-third
looks like with two's complement representation and a length of 32 bits.
It looks like this:

00000000000000000000000000000000

Two's-complement is a representation for signed integers, which cannot
represent fractional values.

If you're asking what 1.0/3.0 looks like in a floating-point
representation, it depends on which representation is used. The IEEE
standard is most common; a web search should turn up documentation.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 26 '07 #12
Keith Thompson <ks***@mib.orgwrites:
"Lane Straatman" <in*****@invalid.netwrites:
>I'm trying to think of what one-third looks like when represented by two's
complement. What is its length? I'm not schur. It would be a DWORD in
assembly. In c, it would be (I think:)
float r = (float)(one third)

float r = 1.0/3.0;
[snip]

I thought Lane Straatman's name looked familiar; I should have checked
before posting a followup.

Lane Straatman, in my opinion, is a troll; see
<http://groups.google.com/group/comp.lang.c/msg/a4cc7d2a141439a7>,
which references
<http://groups.google.com/group/comp.std.c/msg/d91bae8783a38bde>.

Until and unless he publicly apologizes for his previous boorish
behavior, he'll get no further help from me. Others, as always, will
do as they wish.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 26 '07 #13
On Mar 27, 8:59 am, Martin Ambuhl <mamb...@earthlink.netwrote:
printf("As float 1/3 = %.*g\nHex: ", FLT_DIG, fltvalue);
for (i = 0; i < sizeof fltvalue; i++)
printf("%u ", fltchars[i]);

Here is how one implementation stores 1/3.
As float 1/3 = 0.333333
Hex: 171 170 170 62
That's an unconventional use of "Hex" :)

Mar 26 '07 #14
On Mar 27, 8:55 am, "Lane Straatman" <inva...@invalid.netwrote:
The sign will take a bit. The mantissa is the a in the a**x.
The exponent is the exponent, x.
In the implementation I have looked at, it is
a * 2**x

where 'a' is represented as a binary fraction between 0 and 1,
for example 0.75 would be 110000...0

Note that you would never need 'a' being less than 0.5, because
you could then scale it by doubling 'a' and subtracting one from 'x'.
So you can actually drop the first bit of 'a', assuming it always
to be 1, and use that storage for the sign bit.

Mar 26 '07 #15

"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
Keith Thompson <ks***@mib.orgwrites:
>"Lane Straatman" <in*****@invalid.netwrites:
>>I'm trying to think of what one-third looks like when represented by
two's
complement. What is its length? I'm not schur. It would be a DWORD in
assembly. In c, it would be (I think:)
float r = (float)(one third)

float r = 1.0/3.0;

[snip]

I thought Lane Straatman's name looked familiar; I should have checked
before posting a followup.

Lane Straatman, in my opinion, is a troll; see
<http://groups.google.com/group/comp.lang.c/msg/a4cc7d2a141439a7>,
which references
<http://groups.google.com/group/comp.std.c/msg/d91bae8783a38bde>.

Until and unless he publicly apologizes for his previous boorish
behavior, he'll get no further help from me. Others, as always, will
do as they wish.
Your "help" has consisted of shitting on my threads; your abscence is
welcome. I liked you a lot more as the Other Keith.
--
Mar 26 '07 #16
Old Wolf wrote:
On Mar 27, 8:59 am, Martin Ambuhl <mamb...@earthlink.netwrote:
> printf("As float 1/3 = %.*g\nHex: ", FLT_DIG, fltvalue);
for (i = 0; i < sizeof fltvalue; i++)
printf("%u ", fltchars[i]);

Here is how one implementation stores 1/3.
As float 1/3 = 0.333333
Hex: 171 170 170 62

That's an unconventional use of "Hex" :)
Yes, I erred. Thanks for noticing.
To the OP: my "%u " should be "%x ".

Mar 26 '07 #17

"Fred Kleinschmidt" <fr******************@boeing.comwrote in message
news:JF********@news.boeing.com...
>
"Lane Straatman" <in*****@invalid.netwrote in message
news:5K******************************@comcast.com. ..
>>
"Army1987" <pl********@for.itwrote in message
news:eu**********@tdi.cu.mi.it...
>>>
"Lane Straatman" <in*****@invalid.netha scritto nel messaggio
news:es******************************@comcast.co m...
I'm trying to think of what one-third looks like when represented by
two's complement. What is its length? I'm not schur. It would be a
DWORD in assembly. In c, it would be (I think:)
float r = (float)(one third)
My syntax is somewhat wanting.

I think the question can be stated unambiguously if I ask what
one-third looks like with two's complement representation and a length
of 32 bits.

Two's complement is a representation for signed integers.
What did you *really* mean?
I knew I was in trouble there. What possiblities does one have for
representing one-third as a float in C, in particular with 32 bits?

00111110101010101010101010101011
I'm actually going to try to code this tonight, but there's no guarantees
because I've got a poker game to go to. I think that Fred's answer is going
to be what my C IDE on windows has. I would be surprised to find popular
implementations that don't waffle between zero and one on this for the
bigger part of it.

It's been a while since I put a semicolon on the end of an executable
statement.
--
LS
Mar 27 '07 #18
>"Lane Straatman" <in*****@invalid.netha scritto nel messaggio
>news:es******************************@comcast.com ...
>>I think the question can be stated unambiguously if I ask what one-third
looks like with two's complement representation and a length of 32 bits.
>"Army1987" <pl********@for.itwrote in message
news:eu**********@tdi.cu.mi.it...
>Two's complement is a representation for signed integers.
What did you *really* mean?
Indeed.

In article <5K******************************@comcast.com>
Lane Straatman <in*****@invalid.netwrote:
>I knew I was in trouble there. What possiblities does one have for
representing one-third as a float in C, in particular with 32 bits?
The format of floating-point numbers is specified quite loosely.

For some details on some actual representations (particularly the
now-common IEEE format), see <http://web.torek.net/torek/c/numbers.html>.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Mar 27 '07 #19
Lane Straatman wrote:
"Keith Thompson" <ks***@mib.orgwrote in message
.... snip ...
>>
I thought Lane Straatman's name looked familiar; I should have
checked before posting a followup.

Lane Straatman, in my opinion, is a troll; see
<http://groups.google.com/group/comp.lang.c/msg/a4cc7d2a141439a7>,
which references
<http://groups.google.com/group/comp.std.c/msg/d91bae8783a38bde>.

Until and unless he publicly apologizes for his previous boorish
behavior, he'll get no further help from me. Others, as always,
will do as they wish.

Your "help" has consisted of shitting on my threads; your abscence
is welcome. I liked you a lot more as the Other Keith.
Looks like Keith was right - PLONK.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Mar 27 '07 #20

"CBFalconer" <cb********@yahoo.comwrote in message
news:46***************@yahoo.com...
Lane Straatman wrote:
>"Keith Thompson" <ks***@mib.orgwrote in message
... snip ...
>>>
I thought Lane Straatman's name looked familiar; I should have
checked before posting a followup.

Lane Straatman, in my opinion, is a troll; see
<http://groups.google.com/group/comp.lang.c/msg/a4cc7d2a141439a7>,
which references
<http://groups.google.com/group/comp.std.c/msg/d91bae8783a38bde>.

Until and unless he publicly apologizes for his previous boorish
behavior, he'll get no further help from me. Others, as always,
will do as they wish.

Your "help" has consisted of shitting on my threads; your abscence
is welcome. I liked you a lot more as the Other Keith.

Looks like Keith was right - PLONK.
I won't mind your absence either, OS bigot.
--
Mar 27 '07 #21
Lane Straatman wrote:
>
I'm trying to think of what one-third looks like when represented by two's
complement. What is its length? I'm not schur. It would be a DWORD in
assembly. In c, it would be (I think:)
float r = (float)(one third)
My syntax is somewhat wanting.

I think the question can be stated unambiguously if I ask what one-third
looks like with two's complement representation and a length of 32 bits.
/*
** two's complement representation is for negative integers.
*/

/* BEGIN output from bitstr.c */

0.333333 = 00111110101010101010101010101011

/* END output from bitstr.c */

/* BEGIN bitstr.c */

#include <limits.h>
#include <stdio.h>

#define STRING "%15f = %s\n"
#define E_TYPE float
#define INITIAL ((float)(1.0 / 3))
#define FINAL INITIAL
#define INC(E) ((E) *= 2)

typedef E_TYPE e_type;

void bitstr(char *str, const void *obj, size_t n);

int main(void)
{
e_type e;
char ebits[CHAR_BIT * sizeof e + 1];

puts("\n/* BEGIN output from bitstr.c */\n");
e = INITIAL;
bitstr(ebits, &e, sizeof e);
printf(STRING, e, ebits);
while (FINAL e) {
INC(e);
bitstr(ebits, &e, sizeof e);
printf(STRING, e, ebits);
}
puts("\n/* END output from bitstr.c */");
return 0;
}

void bitstr(char *str, const void *obj, size_t n)
{
unsigned mask;
const unsigned char *byte = obj;

while (n-- != 0) {
mask = ((unsigned char)-1 >1) + 1;
do {
*str++ = (char)(mask & byte[n] ? '1' : '0');
mask >>= 1;
} while (mask != 0);
}
*str = '\0';
}

/* END bitstr.c */
--
pete
Mar 28 '07 #22
Lane Straatman wrote:
"Harald van D?k" <tr*****@gmail.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
>Lane Straatman wrote:
>>"Army1987" <pl********@for.itwrote in message
news:eu**********@tdi.cu.mi.it...
"Lane Straatman" <in*****@invalid.netha scritto nel messaggio
news:es******************************@comcast.c om...
I'm trying to think of what one-third looks like when represented by
two's complement. What is its length? I'm not schur. It would be a
DWORD in assembly. In c, it would be (I think:)
float r = (float)(one third)
My syntax is somewhat wanting.
>
I think the question can be stated unambiguously if I ask what
one-third
looks like with two's complement representation and a length of 32
bits.
Two's complement is a representation for signed integers.
What did you *really* mean?
I knew I was in trouble there. What possiblities does one have for
representing one-third as a float in C, in particular with 32 bits?
Every possible bit pattern is a potential valid representation of the
best approximation to one-third, or even the exact representation of
it. There are practically no requirements on how a float is stored in
memory.
That's what I thought. How is it usually represented?
00111110 10101010 10101010 10101011
Exp = 125 (-1)
11111111
Man = .10101010 10101010 10101011
3.33333343e-01
0.333333

...is one possibility.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Mar 28 '07 #23

"pete" <pf*****@mindspring.comwrote in message
news:46***********@mindspring.com...
Lane Straatman wrote:
>[what's one third look like]
/* BEGIN bitstr.c */

#include <limits.h>
#include <stdio.h>

#define STRING "%15f = %s\n"
#define E_TYPE float
#define INITIAL ((float)(1.0 / 3))
#define FINAL INITIAL
#define INC(E) ((E) *= 2)

typedef E_TYPE e_type;

void bitstr(char *str, const void *obj, size_t n);

int main(void)
{
e_type e;
char ebits[CHAR_BIT * sizeof e + 1];

puts("\n/* BEGIN output from bitstr.c */\n");
e = INITIAL;
bitstr(ebits, &e, sizeof e);
printf(STRING, e, ebits);
while (FINAL e) {
INC(e);
bitstr(ebits, &e, sizeof e);
printf(STRING, e, ebits);
}
puts("\n/* END output from bitstr.c */");
return 0;
}

void bitstr(char *str, const void *obj, size_t n)
{
unsigned mask;
const unsigned char *byte = obj;

while (n-- != 0) {
mask = ((unsigned char)-1 >1) + 1;
do {
*str++ = (char)(mask & byte[n] ? '1' : '0');
mask >>= 1;
} while (mask != 0);
}
*str = '\0';
}

/* END bitstr.c */
/* BEGIN output from bitstr.c */

0.333333 = 00111110101010101010101010101011

/* END output from bitstr.c */
Clean as a whistle.
--
LS
Mar 31 '07 #24
On Mon, 26 Mar 2007 22:21:28 +0100, "Malcolm McLean"
<re*******@btinternet.comwrote:
<snip>
Floating point numbers are basically just the same, but in binary. Since the
By convention, at present. C doesn't require binary for floating point
(it does for integers) and there are some fairly serious attempts
among the numerics people to move to decimal floating point.
leading most significant binary digit must always be one, most
representations including IEEE save a bit by omitting it. There is one
exception to this rule, zero, so zero is represented specially by all bits
Yes, and zero is all-bits-zero except optionally sign.
zero. Since zero is 10^-inf, it makes sense to store exponents in a sign
magnitude encoding rather than twos complement, so that 0 is the lowest, 1
= -127 or whatever, and so on. The sign bit is self explanatory.
The IEEE representation of the exponent is biased, not S&M.

<snip rest>

Apr 15 '07 #25

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Rick | last post by:
I need to store a date prior to the unix epoch, any pointers? -- Rick Digital Printing www.intelligence-direct.com
8
by: Rade | last post by:
Following a discussion on another thread here... I have tried to understand what is actually standardized in C++ regarding the representing of integers (signed and unsigned) and their conversions....
10
by: pemo | last post by:
As far as I understand it, a trap representation means something like - an uninitialised automatic variable might /implicitly/ hold a bit-pattern that, if read, *might* cause a 'trap' (I'm not...
24
by: hammer1234 | last post by:
Hi I am wondering if there is a way of using the underlying bit representations of floats. I am interested in creating a violation in MISRA C:2004 of rule "The underlying bit representations...
17
by: Army1987 | last post by:
If uMyInt_t is an unsigned integral type, is the following a necessary and sufficient condition that uMyInt_t has no trap representation? (uMyInt_t)(-1) >CHAR_BIT*sizeof(uMyInt_t)-1 That is,...
7
by: thamizh.veriyan | last post by:
Hi, I am new to this community. I have a doubt regarding trap representations. I read in IBM's website that something like this is legal: int main(){ int x=3; {
11
by: vippstar | last post by:
Hello Let's assume CHAR_BIT == 8, sizeof (int) == 4 and INT_MAX == 32767 (that'd mean int has 32 bits, of which only the 15 are value bits) Now, my question is, are the value bits required to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.