Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

Calculating values from string

Posted on 2011-03-09
Medium Priority
281 Views
I have an input string "BEA4F1" into which is encoded the following printer colour settings.

10 bits are colour intensity (0 to 1023)
10 bits are colour range ( 0 to 1023)
4 bits are for colour (0 to 15)

So an example message would be  "BEA4F1"

intensity = 762 = 1011111010
range     = 591 = 1001001111
colour    = 1   = 0001

So binary (24 bits = 1011 1110 1010 0100 1111 0001 = "BEA4F1"

how do I get intensity, range and colour values back from string "BEA4F1"?

Thanks

0
Question by:oddszone
[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
• 2

LVL 53

Expert Comment

ID: 35082466
Code below to get them back in binary
``````string x = hex2binary("BEA4F1");

string intensity = x.Substring(0,10);
string range = x.Substring(10,10);
string colour = x.Substring(20, 4);

static string hex2binary(string hexvalue)
{
string binaryval = "";
binaryval = Convert.ToString(Convert.ToInt32(hexvalue, 16), 2);
return binaryval;
}
``````
0

LVL 53

Accepted Solution

Dhaest earned 2000 total points
ID: 35082496
Also added the convertion to integer-values
``````static void Main(string[] args)
{
string x = hex2binary("BEA4F1");

string sIntensity = x.Substring(0,10);
string sRange = x.Substring(10,10);
string sColour = x.Substring(20, 4);

int intensity = Convert.ToInt32(sIntensity, 2);
int range = Convert.ToInt32(sRange, 2);
int colour = Convert.ToInt32(sColour, 2);

}

static string hex2binary(string hexvalue)
{
string binaryval = "";
binaryval = Convert.ToString(Convert.ToInt32(hexvalue, 16), 2);
return binaryval;
}
``````
0

Author Closing Comment

ID: 35082635
Spot on thanks !
0

Featured Post

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month7 days, 21 hours left to enroll