Question Writing BitArray to Console

Keith_K

New member
Joined
Mar 15, 2021
Messages
3
Programming Experience
Beginner
Hello, friends.

I wanted to learn about bit arrays and so, I sought an example,
(PS - you can stop reading the example code after line 22):

The following example demonstrates the use of BitArray class:
using System;
using System.Collections;

namespace CollectionsApplication {
   class Program {
      static void Main(string[] args) {
         //creating two  bit arrays of size 8
         BitArray ba1 = new BitArray(8);
         BitArray ba2 = new BitArray(8);
       
         byte[] a = { 60 };
         byte[] b = { 13 };
       
         //storing the values 60, and 13 into the bit arrays
         ba1 = new BitArray(a);
         ba2 = new BitArray(b);
       
         //content of ba1
         Console.WriteLine("Bit array ba1: 60");
       
         for (int i = 0; i < ba1.Count; i++) {
            Console.Write("{0, -6} ", ba1[i]);
         }
         Console.WriteLine();
       
         //content of ba2
         Console.WriteLine("Bit array ba2: 13");
       
         for (int i = 0; i < ba2.Count; i++) {
            Console.Write("{0, -6} ", ba2[i]);
         }
         Console.WriteLine();
         BitArray ba3 = new BitArray(8);
         ba3 = ba1.And(ba2);
       
         //content of ba3
         Console.WriteLine("Bit array ba3 after AND operation: 12");
       
         for (int i = 0; i < ba3.Count; i++) {
            Console.Write("{0, -6} ", ba3[i]);
         }
         Console.WriteLine();
         ba3 = ba1.Or(ba2);
       
         //content of ba3
         Console.WriteLine("Bit array ba3 after OR operation: 61");
       
         for (int i = 0; i < ba3.Count; i++) {
            Console.Write("{0, -6} ", ba3[i]);
         }
         Console.WriteLine();

         Console.ReadKey();
      }
   }
}

I want to understand the use of the numbers 0 and -6 that are being written to the console. They don't seem like indices. What are they about? Why those specific numbers? Thanks.
 
This explains everything you need to know on the subject:

 
Spesifically from Format Item Syntax:
{ index[,alignment][:formatString]}
 
Back
Top Bottom