title: What is a better way to pack 4 ints into ulong?
body: <p>I need to pack several int values(each value only ranging from 0 to 999) into ulong. I have a working method like below but can it be optimized?</p>
  
  <p>I know it hurts your eyes with lots of 0's, sorry.</p>
  
  <pre><code>public class Test  {
  
      public void Start() {
          ulong testValue = 444333222111;
  
          Debug.Log(GetValue1(testValue) + " " + GetValue2(testValue) + " " + GetValue3(testValue) + " " + GetValue4(testValue)); // = 111 222 333 444
  
          SetValue1(ref testValue, 55);
          SetValue2(ref testValue, 9);
          SetValue3(ref testValue, 111);
          SetValue4(ref testValue, 999);
  
          Debug.Log(testValue); // = 999111009055
          Debug.Log(GetValue1(testValue) + " " + GetValue2(testValue) + " " + GetValue3(testValue) + " " + GetValue4(testValue)); // = 55 9 111 999
      }
  
      public int GetValue1(ulong i) =&gt; (int)(i % 1000);
      public void SetValue1(ref ulong i, int value) =&gt; i = i / 1000 * 1000 + (ulong)value;
  
      public int GetValue2(ulong i) =&gt; (int)(i % 1000000 / 1000);
      public void SetValue2(ref ulong i, int value) =&gt; i = i / 1000000 * 1000000 + (ulong)value * 1000 + i % 1000;
  
      public int GetValue3(ulong i) =&gt; (int)(i % 1000000000 / 1000000);
      public void SetValue3(ref ulong i, int value) =&gt; i = i / 1000000000 * 1000000000 + (ulong)value * 1000000 + i % 1000000;
  
      public int GetValue4(ulong i) =&gt; (int)(i % 1000000000000 / 1000000000);
      public void SetValue4(ref ulong i, int value) =&gt; i = i / 1000000000000 * 1000000000000 + (ulong)value * 1000000000 + i % 1000000000;
  
  }
  </code></pre>