Jump to content

converting 24 bit 2s compliment data to a signed integer


DickD

Recommended Posts

Download File:post-4719-1150910981.vi

I am collecting 24 bit words from a serial source as an array and converting them (2 s compliment) to integers I32.

Starting out with a 24 boolean element array I move the sign bit (23) to element 31 after resizing the array to 32 bits. From there it is an array to integer conversion.

It works ok but I am wondering if I am overlooking a more elegant way of doing this.

Thanks

Link to comment
Download File:post-4719-1150910981.vi

I am collecting 24 bit words from a serial source as an array and converting them (2 s compliment) to integers I32.

Starting out with a 24 boolean element array I move the sign bit (23) to element 31 after resizing the array to 32 bits. From there it is an array to integer conversion.

It works ok but I am wondering if I am overlooking a more elegant way of doing this.

Thanks

I do not have LV 8 up on a machine at the moment but assuming you already have the 24 bits in the low 24 bits of an I32, I'd would take advantage of bitwise operations and test the sign bit using a mask of "00000000100000000000000000000" and if the result is NOT =0 then do an or with a mask of "1111111100000000000000000000000"

See image.

post-29-1150914287.jpg?width=400

I would also to the "Or-ing" inside a case structure so that you are not doing work needlessly.

I hope this helps,

Ben

Link to comment
I am collecting 24 bit words from a serial source as an array and converting them (2 s compliment) to integers I32.

Starting out with a 24 boolean element array I move the sign bit (23) to element 31 after resizing the array to 32 bits. From there it is an array to integer conversion.

It works ok but I am wondering if I am overlooking a more elegant way of doing this.

Thanks

Perhaps the attached will be of some use to you.

These little data manipulation problems can be solved in so many ways, since LV has a pretty complete set of polymorphic primitives. The VI I've attached is just one way to get there, I'm sure someone else will come along with a cleaner and/or faster approach :D

Best regards,

Dave

Download File:post-195-1150951577.vi

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.