Extended Posted May 21, 2016 Share Posted May 21, 2016 (edited) İyi günler öncelikle. string asdas = "6F6772616D20"; diye bir verim var rastgele. bunu byte[] PatchFind = { 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x20 }; bu şekilde yazdırmak istiyorum ama bi türlü beceremedim. Şöyle bi mantık kurdum; public static byte[] ByteCevir(string deger) { byte[] asdas = new byte[deger.Length / 2 - 1]; for (int i = 0; i < deger.Length; i+=2) { asdas[i] = 0x + deger.Substring(i, 2); } return asdas; } Burda sorun şu ki asdas = 0x + deger.Substring(i, 2); bu kısmı birleştiremiyorum olduğu gibi yan yana eklemenin yolu yok mu? Yani örneğin 0x6F yapsa kabul edilecek ama + ile birleştirince olmuyor bu mantık. int olan 1 değerinin yanına bir 1 daha koyma mantığı gibi sanıyorum bunu yapmanın yolu var mı? Edited May 21, 2016 by Extended Quote Link to comment Share on other sites More sharing options...
abdullahTR Posted May 21, 2016 Share Posted May 21, 2016 asdas[i] = 0x + deger.Substring(i, 2); visual studio kurulu değil deniyemiyorum ama "0x"+deger.Substring(i,2); deneyebilirmisin Quote Link to comment Share on other sites More sharing options...
Extended Posted May 21, 2016 Author Share Posted May 21, 2016 Yemiyor string türünde veriler. Benim byte olarak sallamam lazım aynı şeyi. Quote Link to comment Share on other sites More sharing options...
abdullahTR Posted May 21, 2016 Share Posted May 21, 2016 http://stackoverflow.com/questions/16072709/converting-string-to-byte-array-in-c-sharp buraya bir bakarmısın Quote Link to comment Share on other sites More sharing options...
Extended Posted May 21, 2016 Author Share Posted May 21, 2016 Oraya baktım da zaten benim veriler byte, çevrilecek bişey yok mesele orda. Byte olarak okutturamıyorum Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted May 21, 2016 Editor Share Posted May 21, 2016 Tam olarak ne istediğini anlamadım açıkcası. Byte[] veriyi çıktı mı almak istiyorsun. Quote Link to comment Share on other sites More sharing options...
MostWanted Posted May 21, 2016 Share Posted May 21, 2016 (edited) byte[] byteCevir(string input) { byte[] converted = new byte[input.Length / 2]; int j = 0; for (int i = 0; i < input.Length - 2 ; i += 2) { converted[j++] = Convert.ToByte(input.Substring(i, 2),16); } return converted; } Visual Studio'da normal onluk tabanda gösterecektir ama hexadecimal görünümü açarsan istediğin sonuç olduğunu görürsün. Edited May 21, 2016 by MostWanted 2 Quote Link to comment Share on other sites More sharing options...
KintaRo Posted May 21, 2016 Share Posted May 21, 2016 bende şöyle yapmıştım: string s = "w323424"; byte[] toBytes = Encoding.ASCII.GetBytes(s); string yeniString = ""; foreach (byte item in toBytes) { yeniString += item.ToString(); } MessageBox.Show(yeniString); 2 Quote Link to comment Share on other sites More sharing options...
Extended Posted May 21, 2016 Author Share Posted May 21, 2016 (edited) @MostWanted Teşekkür ederim hocam yalnız aşağıdaki gibi küçük bir değişim yapılmalı: for (int i = 0; i < input.Length - 2 ; i += 2) yerine for (int i = 0; i <= input.Length - 2 ; i += 2) Edited May 21, 2016 by Extended Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.