Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
so i have a task there are 8 colors given and i need to find 9th one
these are the hex codes for colors
1) #AA0099 ? #009966 = #AA99FF
2) #339900 ? #990066 = #AA9966
3) #006699 ? #EF4321 = #??????
what actions do i have to do to get the last color and why ?

What I have tried:

I can't seem to solve the problem I've tried adding them up but couldn't get it, don't know if I'm doing it wrong or its the different thing please help
Posted
Updated 5-Nov-17 14:10pm
v4

Maybe you can just double check your calculations with this?
Hexadecimal to Decimal Converter[^]
 
Share this answer
 
v3
You should review the binary operators "and", "or", "xor", and "not". Once you figure out what operator applies to the first two answers, it's easy to figure out what the answer to the third problem is.
 
Share this answer
 
You are to convert the hex to binary
  #AA0099   1010 1010 0000 0000 1001 1001
? #009966   0000 0000 1001 1001 0110 0110
  =======   =============================
= #AA99FF   1010 1010 1001 1001 1111 1111

and figure out which operation is used. In this example, or can fit, + too ...
Do the same with second example.
 
Share this answer
 
To me it looks like simple math. I think that your second result is wrong.

Here it is in C# as no language was mentioned:
C#
var col1 = new[] { 0xAA0099, 0x339900, 0x006699 };
var col2 = new[] { 0x009966, 0x990066, 0xEF4321 };

for (int i = 0; i < col1.Length; i++)
{
    Console.WriteLine($"{col1[i].ToString("X6")} + {col2[i].ToString("X6")} = {(col1[i] + col2[i]).ToString("X6")}");
}

Which outputs:
AA0099 + 009966 = AA99FF
339900 + 990066 = CC9966
006699 + EF4321 = EFA9BA

After talking with ppolymorphe, you could do the following bitwise:
C#
int[] col1 = new int[] { 0xAA0099, 0x339900, 0x006699 };
int[] col2 = new int[] { 0x009966, 0x990066, 0xEF4321 };

uint mask = (1 << 16) - 1;

for (int i = 0; i < col1.Length; i++)
{
    var answer = (col1[i] | col2[i]) & mask | 0xaa0000;
    Console.WriteLine($"{col1[i].ToString("X6")} ? {col2[i].ToString("X6")} = {answer.ToString("X6")}");
}

Which outputs:
AA0099 ? 009966 = AA99FF
339900 ? 990066 = AA9966
006699 ? EF4321 = AA67B9
 
Share this answer
 
v2
Comments
Patrice T 5-Nov-17 20:44pm    
I fear it is not a simple addition, the second sample id wrong.
Graeme_Grant 5-Nov-17 20:59pm    
A little context would help. I did mention that I thought his 2nd example had the wrong result. But he may not want the red channel altered. Is it RGB, HSL, etc...?
Patrice T 5-Nov-17 21:04pm    
Ok, I didn't read your solution
In fact second sample is correct, it is just not an addition; it is another bitwise operation.
Graeme_Grant 5-Nov-17 21:14pm    
updated to give same answers... ;)
Patrice T 5-Nov-17 21:37pm    
Still wrong, the answer is the only operator you didn't used ^.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900