Solved

help ( urgent)

Posted on 1997-04-28
1
212 Views
Last Modified: 2012-05-04
I have written the following program that allows the user to enter a set of numbers and then store them in an array.

My next step is to take each number and perform some shift operation on it.

My first question is :
How can I store the number in a 16 bit word length inside the computer.

Second question :
If for example the first element in the array is 6 which is 0000000000000110 in binary ( 16 bit word length ), how can I  mask it so that I can store bits 3 to 6 as a number "in this case it is 0".


Cheers.
0
Comment
Question by:a9628657
1 Comment
 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
ID: 1163019
1. How can I store the number in a 16 bit word length inside the computer.?

You can use the data type: unsigned short.
unsigned short nNumArray[20];


2. If for example the first element in the array is 6 which is 0000000000000110 in binary ( 16 bit word length ), how can I mask it so that I can store bits 3 to 6 as a number "in this case it is 0".

unsigned short nMaskedResult = nNumArray[0] & 0x0078;
unsigned short nShiftedResult = nMaskedResult >> 3;


0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

770 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