|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
HEX char -- > its comlementwhat is the smartest function that maps the char on the left to the char on the right (I want to complement an hexadecimal string, like making a negative color). 0 -> f 1 -> e 2 -> d 3 -> c 4 -> b 5 -> a 6 -> 9 7 -> 8 8 -> 7 9 -> 6 a or A -> 5 b or B -> 4 c or C -> 3 d or D -> 2 e or E -> 1 f or F -> 0 If there is something able to map in one shot a whole string to its "complement" would be even better. -Pam pamelaflue***@libero.it wrote:
Show quoteHide quote > 0 -> f One way is like this> 1 -> e > 2 -> d > 3 -> c > 4 -> b > 5 -> a > 6 -> 9 > 7 -> 8 > 8 -> 7 > 9 -> 6 > a or A -> 5 > b or B -> 4 > c or C -> 3 > d or D -> 2 > e or E -> 1 > f or F -> 0 > > If there is something able to map in one shot a whole string > to its "complement" would be even better. Dim S As String = "0123456789ABCDEF" Console.WriteLine(S) For Each C As Char In S Console.Write("{0:X}", (Not Integer.Parse(C.ToString(), Globalization.NumberStyles.AllowHexSpecifier) And 15)) Next if I understand what you want correctly. > Dim S As String = "0123456789ABCDEF" Beautiful. Thanks you very much, Branco and Martin. Both these solution> Console.WriteLine(S) > For Each C As Char In S > Console.Write("{0:X}", (Not Integer.Parse(C.ToString(), >Globalization.NumberStyles.AllowHexSpecifier) And 15)) > Next > Function NegHex(ByVal Hex As String) As String > 'Converts the hex value to integer > Dim V As Int32 = Convert.ToInt32(Hex, 16) .... look very smart. I like them. -P pamelaflue***@libero.it wrote:
Show quoteHide quote > Hi You can use the Not operator (which complements the bits of a given> what is the smartest function that maps the char on the left to > the char on the right (I want to complement an hexadecimal string, > like making a negative color). > > 0 -> f > 1 -> e > 2 -> d > 3 -> c > 4 -> b > 5 -> a > 6 -> 9 > 7 -> 8 > 8 -> 7 > 9 -> 6 > a or A -> 5 > b or B -> 4 > c or C -> 3 > d or D -> 2 > e or E -> 1 > f or F -> 0 > > If there is something able to map in one shot a whole string > to its "complement" would be even better. integer) or Xor the integer value with -1, whichever you prefer. Anyway, you must convert back and forth, from hex to integer to hex again... Function NegHex(ByVal Hex As String) As String 'Converts the hex value to integer Dim V As Int32 = Convert.ToInt32(Hex, 16) 'Defines a mask to the minimum number of chars expected Dim S As Integer = Hex.Length Dim Mask As String = String.Format("x{0}", S) 'Inverts the value and converts it back to hex, extracting just 'the number of chars presented in the original string Return Right((V Xor -1).ToString(Mask), S) 'The above might as well be the following 'Return Right((Not V).ToString(Mask), S) End Function HTH. Regards, Branco.
Extending an Abstract class that uses a Generic Parameter
Get all forms contained in another project Check for Updates Try to delete a worksheet in Excel WebBrowser Control can't create dll properly File Not Accessed Restricting the resizing of forms Adding row to data table in .net 2.0 Code Analyzers |
|||||||||||||||||||||||