Re: [linux-audio-dev] 24 bits, 2's complement - help!

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] 24 bits, 2's complement - help!
From: Benno Senoner (sbenno_AT_gardena.net)
Date: la tammi  15 2000 - 12:32:01 EST


On Sat, 15 Jan 2000, Paul Barton-Davis wrote:
>
> So a 32 bit unit containing a 24 bit quantity that just happens to
> look like this is seen by the processor as a number that is larger
> than the signed 24 bit minimum value.
>
> I am totally confused. System architecture rather than bytes and bits
> was always my interest in programming, and I could use some
> help. Clearly. I imagine its very simple, and just something that i
> never had to learn in the last 13 years :)
>

it's called sign extension:

take the negative 24bit value: 11010111 01010111 01100010

(bit 23 = 1)
                                             
in order to be represented correctly on a 32bit field, you
have to fill the left-most 8bits with ones if bit 23=1 else with zeroes.

when converting 16bit to 32bit the C compiler does this automatically,
Most CPUs have an asemmbly instruction to sign-extend the values,
otherwise the compile must do this in software.

or if you want shift left by 8 positions and leave the right 8bits zero.

if you want to convert 24bit ints to 16bit ints, cut the rightsmost 8bits away
the sign will be ok.

assume you have a 24bit int padded with 8bits of zeroes.
just take the uppermost 16bits and copy these into a signed int.

still more doubts ?

Benno.


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : pe maalis 10 2000 - 07:23:26 EST