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
Solved

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

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
Adobe Customization Wizard XI issues 26 255
withoutTen challenge 14 131
C Programming - If Statement 8 82
Bartender label printing - switch on and off graphics 3 54
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

856 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