Solved

Convert short int to one byte

Posted on 2006-07-11
3
598 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
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
manish_regmi earned 450 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 50 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

914 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now