Solved

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

Posted on 2012-03-16
2
391 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 500 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

688 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