question for the guru's about data types

Quote:

> > I am loading a file containing 14 4-byte numbers.

> > A hex-dump of the file looks like this:

> > 0000 000C 0000 000C 0000 000C 0000 000C

> > 0000 091A 0000 1025 0000 0140 0000 0014

> > 0000 091A 0000 09F3 0000 1AF3 0000 1A0C

> > 0000 1025 0000 1BCE

> > I know above numbers represent these numbers:

> > 0,0,0,0,52,106,17,3,52,58,68,80,106,279

> Are you quite sure? It must be a pretty odd computer which represents

> 0 as 0x0000000C; this would usually be either 12 or some large number

> (depending on the endianness of your machine, and also whether these

> numbers are signed). It's possible they're in some kind of floating

> point format, I suppose, but even then 0.0 usually comes out as all

> zeroes.

I think you misunderstood.

0: 0000 000C

0: 0000 000C

0: 0000 000C

0: 0000 000C

52: 0000 091A

106: 0000 1025

17: 0000 0140

3: 0000 0014

52: 0000 091A

58: 0000 09F3

68: 0000 1AF3

80: 0000 1A0C

106: 0000 1025

279: 0000 1BCE

This is quite a weird format.

Perhaps it's some sort of Hamming code.

A Hamming code is a code where several parity bits are added in

interesting places (N parity bits for 2^N data bits) to be able to

detect and correct a single bit error.

Did you get these data from a serial link or something else error

prone, like a barcode reader?

A parity bit's value is set to a value that makes the total number

of 1's in the number (incl. parity bit) even ("Even parity")

or odd ("Odd parity").

In a Hamming code, every parity bit checks its own group of bits,

e.g.:

1st parity bit checks 0x0x0x0x0x0x0x0x

2nd parity bit checks 00xx00xx00xx00xx

3rd parity bit checks 0000xxxx0000xxxx

etc.

I don't remember what the best place for the parity bits was, though.

Bits 0 and 1 are likely candidates for (odd) parity bits,

since 0 is represented by 0000 000C (or 00...011 binary).

Bits 0 and 1 bring the total nr. of 1's in there respective areas

to an odd number (being 1).

I THINK the other parity bits are not set to 1 because they each

check on one of the first parity bits, but I'm not at all sure

about that.

You probably have 16 data bits, 4 parity bits and 4 unused bits.

Can you get the values for 1, 2, 3, 4 etc. and for e.g. 254, 255, 256,

65534, 65535, and all powers of 2?

I'll dig up ye ol' dig'tal tech books at home and puzzle on this

for a wee while...

Of course, none of this is on-topic for comp.lang.c. :-(

--

CMG Telecommunications & Utilities B.V.

Division Advanced Technology Tel: +31 30 23 39 300

P.O.Box 8038 Fax: +31 30 23 39 495

3503 RA Utrecht, The Netherlands