• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 605
  • Last Modified:

Convert short int to one byte

Hello,

Simple, quick question - how do you convert an unsigned short int to one byte?
0
jewee
Asked:
jewee
  • 2
2 Solutions
 
manish_regmiCommented:
did you mean this;

unsigned char low, high;
unsigned short val = 0x7867;

low = val & 0xFF;
high = val >> 8;

regards
Manish Regmi
0
 
manish_regmiCommented:
just assigning the value will loose data if it is greater than 8 bits;

unsigned char bt = (unsigned char)sixteenbit value

regards
Manish
0
 
bastibartelCommented:
Hi jewee,
Simple, quick answer - you don't.
manish_regmi posted your options  

quote: http://home.att.net/~jackklein/c/inttypes.html
An unsigned short can hold all the values between 0 and USHRT_MAX inclusive. USHRT_MAX must be at least 65535.

or: http://en.wikibooks.org/wiki/C++_Programming/Data_Types_Reference

Cheers!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now