Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Convert short int to one byte

Posted on 2006-07-11
3
Medium Priority
?
604 Views
Last Modified: 2008-02-26
Hello,

Simple, quick question - how do you convert an unsigned short int to one byte?
0
Comment
Question by:jewee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
manish_regmi earned 1800 total points
ID: 17082399
did you mean this;

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

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

regards
Manish Regmi
0
 
LVL 8

Expert Comment

by:manish_regmi
ID: 17082424
just assigning the value will loose data if it is greater than 8 bits;

unsigned char bt = (unsigned char)sixteenbit value

regards
Manish
0
 
LVL 5

Assisted Solution

by:bastibartel
bastibartel earned 200 total points
ID: 17082544
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question