5

Possible Duplicate:
Converting long string of binary to hex c#

nyI'm looking for a way to convert a string of binary to a hex string.

the binary string has four positions. the binary string looks something like this

string binarystring= "1011";

output string should be like this

output string="B";

is there any way to convert a string of binary into hex?

Community
  • 1
  • 1
user2020261
  • 67
  • 1
  • 1
  • 4
  • http://stackoverflow.com/questions/5612306/converting-long-string-of-binary-to-hex-c-sharp – Bali C Feb 01 '13 at 09:29
  • I just ran a search on Google for "c# convert binary string to hex" and the first 2 results were http://stackoverflow.com/questions/5612306/converting-long-string-of-binary-to-hex-c-sharp and http://stackoverflow.com/questions/6617284/c-sharp-how-convert-large-hex-string-to-binary and in **both**, the answer you're looking for is in the question, highlighted too. So what's your excuse for being lazy? – Nolonar Feb 01 '13 at 11:20

1 Answers1

16
Convert.ToInt32("1011", 2).ToString("X");

For more information about the string value used with ToString() as its parameter, check the following documentation:

https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx

Soroush Falahati
  • 2,196
  • 1
  • 27
  • 38
  • This Q has been marked as a duplicate. Your answer is better than the one in the other Q, you should post it there too! – Peter Morris Sep 10 '14 at 16:47