Click here to Skip to main content
16,020,990 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello

someone could convert this code from java to c#.

sb2.Append(String.Format("-%02X", new Object[] { Byte.valueOf(b1) }));
  sb2.Append(String.Format("%02X", new Object[] { Byte.valueOf(b2) }));


thanks
regards

What I have tried:

the problem is the byte.valueof… i dont know how to express it in c#
Posted
Updated 14-May-19 2:49am

 
Share this answer
 
Try Byte.TryParse Method (System) | Microsoft Docs[^]
C#
string b1 = "+120";
byte b1b;
if (!byte.TryParse(b1, out b1b)) return;
Then use bib in your array.
Or better:
C#
string b1 = "+120";
byte b1b;
if (!byte.TryParse(b1, out b1b)) return;
sb2.AppendFormat($"-{b1b:X2}");
 
Share this answer
 
Assuming sb2 is a StringBuilder object and you want the hex value...

C#
sb2.AppendFormat("{0:X2}{1:X2}", b1, b2));
 
Share this answer
 

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