Jump to content

Bytes Verileri Birleştirme


Extended
 Share

Recommended Posts

İ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 by Extended
Link to comment
Share on other sites

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 by MostWanted
  • Like 2
Link to comment
Share on other sites

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);

 

  • Like 2
Link to comment
Share on other sites

@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 by Extended
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...