我指针不能用,怎么把指针去掉代码还是同一个意思c,c#,c++
private static unsafe uint[] ToUInt32Array(byte[] data, bool includeLength)
{
uint[] numArray;
int length = data.Length;
int index = ((length & 3) != 0) ? ((length >> 2) + 1) : (length >> 2);
if (!includeLength)
{
numArray = new uint[index];
}
else
{
numArray = new uint[index + 1];
numArray[index] = (uint) length;
}
for (int i = 0; i < length; i++)
{
uint* numPtr1 = &(numArray[i >> 2]);
numPtr1[0] |= (uint) (data[i] << (((i & 3) << 3) & 0x1f));
}
return numArray;
}
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using System;
namespace HelloWorldApplication
{
class HelloWorld
{
private static unsafe uint[] ToUInt32Array(byte[] data, bool includeLength)
{
uint[] numArray;
int length = data.Length;
int index = ((length & 3) != 0) ? ((length >> 2) + 1) : (length >> 2);
if (!includeLength)
{
numArray = new uint[index];
}
else
{
numArray = new uint[index + 1];
numArray[index] = (uint) length;
}
for (int i = 0; i < length; i++)
{
uint* numPtr1 = &(numArray[i >> 2]);
numPtr1[0] |= (uint) (data[i] << (((i & 3) << 3) & 0x1f));
}
return numArray;
}
private static byte[] ToByteArray(uint[] data, bool includeLength)
{
int num = data.Length << 2;
if (includeLength)
{
int num2 = (int) data[data.Length - 1];
num -= 4;
if ((num2 < (num - 3)) || (num2 > num))
{
return null;
}
num = num2;
}
byte[] buffer = new byte[num];
for (int i = 0; i < num; i++)
{
buffer[i] = (byte) (data[i >> 2] >> (((i & 3) << 3) & 0x1f));
}
return buffer;
}
private static uint[] Decrypt(uint[] v, uint[] k)
{
int n = v.Length - 1;
if (n < 1)
{
return v;
}
if (k.Length < 4)
{
uint[] Key = new uint[4];
k.CopyTo(Key, 0);
k = Key;
}
uint z = v[n], y = v[0], delta = 0x9E3779B9, sum, e;
int p, q = 6 + 52 / (n + 1);
sum = unchecked((uint)(q * delta));
while (sum != 0)
{
e = sum >> 2 & 3;
for (p = n; p > 0; p--)
{
z = v[p - 1];
y = unchecked(v[p] -= (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z));
}
z = v[n];
y = unchecked(v[0] -= (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z));
sum = unchecked(sum - delta);
}
return v;
}
static void Main(string[] args)
{
/* 我的第一个 C# 程序*/
String aaa = "字符串1";
Console.WriteLine(aaa);
byte[] buffer = Encoding.UTF8.GetBytes(aaa);
foreach(var item in buffer)
{
Console.Write(item + " ");
}
Console.WriteLine("\n换行");
byte[] bbb = Encoding.UTF8.GetBytes("字符串2");
foreach(var item in bbb)
{
Console.Write(item + " ");
}
Console.WriteLine("\n换行");
byte[] outBuffer=Decrypt( buffer , bbb);
foreach (var item in outBuffer)
{
Console.Write(item + " ");
}
String la=Encoding.UTF8.GetString(outBuffer);
Console.WriteLine(la);
Console.WriteLine("Hello World!");
Console.ReadKey();
}
}
}
不用指针的话,代码是不行了。就不能用返回数组的方式,必须将数组作为参数传递进来。
指针指向物理内存地址进行调取,不用抓不到
用引用 &