[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

how do I remove the MSB of a value before concatenating it with another?

Posted on 2012-03-16
2
Medium Priority
?
395 Views
Last Modified: 2012-03-16
I am writing to two 7-segment LEDs and each of them are controlled with seven bits. I have each digit I want to display stored as a byte. I need to write the high and low digit values as a concatenation to the 7-segment LEDs.  This is a problem because the MSB of the low digit will become the LSB of the high digit. For example, if I am writing the value 99 to the 7-segment LEDs, "0011000" needs to be written to each 7-segment LED.  But because the values are stored as bytes, "00011000" will be the output value for 9, and the concatentation of 9 and 9 would be 00011000 00011000, and "0110000 0011000" will be written to the LEDs instead of "0011000 0011000". How do I get rid of the low digit MSB before concatenating??
0
Comment
Question by:frostyourself
[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 Comments
 
LVL 16

Accepted Solution

by:
HooKooDooKu earned 2000 total points
ID: 37731964
WORD DoubleDigit;
BYTE LowDigit;
BYTE HighDigit;
... /* set your value for the two digits */
DoubleDigit = (WORD) HighDigit << 8 + (WORD) LowDigit << 1;
DoubleDigit = DoubleDigit >> 1;

Open in new window


Basically, shift the high digit to the 2nd byte, then shift the low digit once.  Then shift both together to the right one.

Now I might have your digits transposed here (i.e. you might need to swap HighDigit with LowDigit). but the idea is still the same.  Utilize the << and >> bit shift operators.  You can first utilize the bit shift on a single byte, then concatenate the two bytes (placing one in the high order byte of a 16-bit word) and then bit shift the whole 16-bit value to get the final value you need for the LED display.
0
 

Author Closing Comment

by:frostyourself
ID: 37731989
Thank you!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.
Suggested Courses

650 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