Solved

Convert short int to one byte

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

747 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

16 Experts available now in Live!

Get 1:1 Help Now