24 bit signed number conversion 
Author Message
 24 bit signed number conversion

I have written code to convert a decimal value to a signed 24 bit binary
value (+/- 8,388,608 bin), the only problem is I am having problems
doing it for negative values.
Any suggestions, thanks in advance


Sat, 07 Apr 2001 03:00:00 GMT  
 24 bit signed number conversion

Quote:

> I have written code to convert a decimal value to a signed 24 bit binary
> value (+/- 8,388,608 bin), the only problem is I am having problems
> doing it for negative values.
> Any suggestions, thanks in advance

Surely you can just convert the number ignoring the sign to binary and
then invert each bit and add one to it (if you want 2's complement).

If you want 1's complement then just invert each bit.

If you just want explicit sign then just invert the first sign bit after
converting the positive number.
--
***************************************
**    EMail Sent By Peter Denton     **


**       Phone: (01274) 232559       **
***************************************
* "I tell you the truth, unless you   *
* change and become like little       *
* children, you will never enter the  *
* kingdom of heaven" - Matthew 18v3   *
***************************************



Sun, 08 Apr 2001 03:00:00 GMT  
 24 bit signed number conversion
Without seeing what you're doing now it's a little difficult to know what
you need to add, but if what you're doing is converting the decimal value to
a string of 1's and 0's, then all you need to do is cast the value into the
32-bit number space (a long integer) and mask off the upper 8 bits.  This
will turn it into an unsigned (technically, positive) value having the same
bit pattern as the signed 24-bit value.  This works whether the value is
negative or positive:

    MyVal& = (CLng(My24bits) And &HFFFFFF) 'unsigned' long

Then just convert the lower 24 bits of that value to a binary string.
Ignore what the value appears to be... the bit pattern is the same and
that's all that matters.

--
     Jim Mack
     MicroDexterity, Inc

     http://www.microdexterity.com



Quote:

>I have written code to convert a decimal value to a signed 24 bit binary
>value (+/- 8,388,608 bin), the only problem is I am having problems
>doing it for negative values.
>Any suggestions, thanks in advance



Sun, 08 Apr 2001 03:00:00 GMT  
 24 bit signed number conversion


schreibt:

Quote:
>I have written code to convert a decimal value to a signed 24 bit binary
>value

When you store the value in a Long variable, it has 32 bits of precision, so
you must fill the exceeding 8 bits with the sign of the 24 bit value:

Dim l as Long
l = value
If l And &h800000 Then l=l Or &hFF000000 ' extend sign

DoDi



Tue, 10 Apr 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. 24-bit bmp to 1-bit conversion

2. bmp 24-bit to 1-bit conversion

3. IMAGELIST and 24 by 24 bit icons...

4. Howto change 24 bit bitmap into 8 bit bitmap in vb

5. 24 bit BMP to 8 bit BMP

6. BMP 24-bit to BMP 1-bit converting

7. Convert 16 bit bmp to 24 bit bmp

8. Converting 16/24 bit image to 8 bit

9. 24-bit to 8-bit bitmaps

10. 24-bit to 1-bit bitmap

11. How to load a 24 bit bmp picture

12. 24-bit audio?

 

 
Powered by phpBB® Forum Software