This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Working with data that was created as "unsigned short"

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have special cameras that output a stream of "unsigned shorts" (as in C) to a file. There are only 12 valid bits and I had assumed that they were stuffed in the LSB so that Java would see them all as positive. I'm at the point where I can display an image with my own code but it's not quite right compared to ImageJ. My calculation of maximum and minimum values are too large, don't match that of ImageJ, and the minimum value is negative. I suspect that the valid bits are the MSB
I'd like to shift the bits to the right but suspect that there will be a conversion to an int which will conserve the sign.

How can I convert these shorts?

TIA
 
author
Posts: 23883
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Nate Lockwood wrote:I have special cameras that output a stream of "unsigned shorts" (as in C) to a file. There are only 12 valid bits and I had assumed that they were stuffed in the LSB so that Java would see them all as positive. I'm at the point where I can display an image with my own code but it's not quite right compared to ImageJ. My calculation of maximum and minimum values are too large, don't match that of ImageJ, and the minimum value is negative. I suspect that the valid bits are the MSB
I'd like to shift the bits to the right but suspect that there will be a conversion to an int which will conserve the sign.

How can I convert these shorts?



A conversion from short to int will "sign extend" the value. So, to avoid that you need to mask out the higher order bits.... Something like...



Henry
 
Nate Lockwood
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that preserves the data. Now to see what happens in my code!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic