?
Solved

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

Posted on 2012-03-16
2
Medium Priority
?
394 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

801 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