Help with rectangle splitting in tikz

tikz-pgftikz-styles

I want to draw something like the following picture. I tried the split tikz library, and tried splitting a rectangle but drawing 32 parts is not happening, it is showing only some parts.

Any help on how can I draw the picture in latex.

Thank you.picture

Best Answer

Here is simple example using a \pic for the rectangles and numbered colors to make the code brief.

\documentclass[tikz,border=2mm]{standalone}

% colors
\definecolor{color0}{HTML}{999999} % gray
\definecolor{color1}{HTML}{FF0000} % red
\definecolor{color2}{HTML}{0000FF} % blue
\definecolor{color3}{HTML}{00FF00} % green
\definecolor{color4}{HTML}{FF9999} % light red
 
\tikzset
{
  pics/my rectangle/.style={% #1 -> list of numbers (colors)
    code={%
      \foreach[count=\j]\i in {#1}
        \fill[color\i] (0.2*\j,0) rectangle (0.2*\j+0.18,0.5); 
      \coordinate (-label) at (3.39,-0.3);
      }},
}

\begin{document}
\begin{tikzpicture}
  \pic  (A) at (0,0) {my rectangle={0,0,1,1,1,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
  \node at (A-label) {$0-31$};
  \pic  (B) at (8,0) {my rectangle={0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,1,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
  \node at (B-label) {$32-63$};
\end{tikzpicture}
\end{document}

enter image description here