Solved

Convert short int to one byte

Posted on 2006-07-11
3
599 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

Suggested Solutions

Title # Comments Views Activity
libcurl and C++ - Post JSON Data 8 1,291
distributed computing in Python 4 122
Digital Output does not have continuity to ground? 3 90
An API detour question 7 84
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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

813 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

12 Experts available now in Live!

Get 1:1 Help Now