Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7526203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:46:19+00:00 2026-05-30T03:46:19+00:00

I have an application where i HAVE to store unsigned short data in a

  • 0

I have an application where i HAVE to store unsigned short data in a double parallel vector to be able to easily move it around. Whenever I actually need the data, I cast them back to unsigned short. I know my data, although saved in a double vector, are well within the range of unsigned short i.e. the values stored are all between 0 and 2^16-1.

Question is, since sizeof(double) = 8 and sizeof(unsigned short) = 2 could this cause data loss when casting? I know one problem is if the data is changed by a small bit when in double form, it might be rounded to another number but that is not my concern right now.

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:46:20+00:00Added an answer on May 30, 2026 at 3:46 am

    You don’t have to cast to assign a short to a double. There is an implicit conversion between short and double.

    double a;
    short b = 42;
    
    a = b;  // no cast, OK as there is an implicit conversion
    

    If you are using 16-bit short and IEEE-754 double precision double there is no loss of precision during the conversion.

    To give some perspective, basically for single precision float, the first positive integer value that cannot be represented is 16777217. So for 16-bit short and double you should be OK 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application which stores data to the persistent store by setting the
We have a WinForms application that uses SQL server to store its data. To
I have some simple doubts. I have an application that store some important data
I have an application which uses DirectByteBuffers to store data, but I'd like to
I have an application that has a Service that uses an ArrayList<Double> to store
I have an application which uses Sql Server Express Edition to store data. I
I have C# application that must store some information into MS SQL that would
I have an application where users can store items. Now each type of account
I have an application that uses Boost.Program_options to store and manage its configuration options.
I have created an application that uses settings.settings to store some user specific settings

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.