The Binary Countdown Protocol is a contention-resolution MAC (Medium Access Control) protocol used on shared broadcast channels. When multiple stations want to transmit simultaneously, each station broadcasts its address as a binary number, bit by bit from the most significant bit (MSB) downward. Stations with a 0 bit at a position where another station has a 1 bit drop out of the contention. The station whose complete binary address survives the entire comparison wins the channel and transmits its frame. This guarantees that the station with the highest binary address always wins each contention round.
This C++ program simulates the Binary Countdown Protocol. Each frame is treated as an 8-bit binary number. The program converts each frame to its decimal equivalent (which represents the station’s binary address), then announces the frames in descending priority order — highest decimal value first — as they would be granted channel access.
C++ Program: Binary Countdown Protocol
#include <iostream.h>
#include <conio.h>
void main()
{
int frameSize; // Number of bits per frame (e.g. 8)
int frameCount; // Number of stations/frames competing
int frameBits[20][20]; // frameBits[i][j] = j-th bit of frame i
cout << "\n Enter Frame Size: ";
cin >> frameSize;
cout << "\n How many frames: ";
cin >> frameCount;
// Read each frame bit by bit
for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
{
cout << "\n Enter Frame " << frameIndex + 1 << " (MSB first): ";
for (int bitIndex = 0; bitIndex < frameSize; bitIndex++)
{
cin >> frameBits[frameIndex][bitIndex];
}
}
// Display all entered frames
cout << "\n Inputted Frames:";
for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
{
cout << "\n";
for (int bitIndex = 0; bitIndex < frameSize; bitIndex++)
{
cout << " " << frameBits[frameIndex][bitIndex];
}
}
// --- Convert each frame from binary to decimal ---
// The decimal value represents the station's binary address priority.
// Frames are stored MSB-first, so we scan from the last column (LSB) to the first (MSB).
int framePriority[20];
for (int frameIndex = 0; frameIndex < 20; frameIndex++)
{
framePriority[frameIndex] = 0; // Initialise all priorities to 0
}
int bitWeight = 1; // Start from the least significant bit (weight = 2^0 = 1)
for (int bitIndex = frameSize - 1; bitIndex >= 0; bitIndex--)
{
for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
{
if (frameBits[frameIndex][bitIndex] == 1)
{
framePriority[frameIndex] = framePriority[frameIndex] + bitWeight;
}
}
bitWeight = bitWeight * 2; // Next bit has twice the weight
}
// --- Announce frames in descending priority order ---
// Scan from the highest possible decimal value down to 0.
// A frame is announced when its priority matches the current scan value,
// preserving strict descending order (highest priority transmits first).
for (int priority = 1000; priority >= 0; priority--)
{
for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
{
if (priority == framePriority[frameIndex])
{
cout << "\n Frame " << frameIndex + 1 << " will be transmitted";
}
}
}
getch();
}
How the Code Works
Step 1 — Input: The user specifies the frame size (number of bits) and the number of competing frames. Each frame is entered bit by bit, MSB first, simulating a station broadcasting its binary address.
Step 2 — Binary to Decimal Conversion: Each frame’s bit pattern is converted to its decimal equivalent. Since frames are stored MSB-first, the loop scans from the last column (the LSB) to the first column (the MSB), doubling the bit weight each step (bitWeight = 1, 2, 4, 8, …). This decimal value is the frame’s contention priority.
Step 3 — Priority-Ordered Announcement: The outer loop counts down from 1000 to 0. Whenever a frame’s priority matches the current count value, that frame is announced as the winner of that contention slot. Because the scan is strictly descending, the highest-priority (highest decimal value) frame is always announced first.
Step 4 — Collision-Free Ordering: No two frames with different binary addresses can win the same slot, because the binary comparison eliminates lower-address stations bit by bit. If two frames have the same bit pattern (same binary address), they are announced together in the same slot.
Sample Output
Enter Frame Size: 8
How many frames: 4
Enter Frame 1 (MSB first): 1
0
1
0
1
0
1
0
Enter Frame 2 (MSB first): 0
1
0
0
0
1
0
1
Enter Frame 3 (MSB first): 1
1
0
0
1
0
1
1
Enter Frame 4 (MSB first): 0
0
1
0
1
0
1
0
Inputted Frames:
1 0 1 0 1 0 1 0
0 1 0 0 0 1 0 1
1 1 0 0 1 0 1 1
0 0 1 0 1 0 1 0
Frame 3 will be transmitted
Frame 1 will be transmitted
Frame 2 will be transmitted
Frame 4 will be transmitted
Output Explanation
The decimal equivalents of the four 8-bit frames are: Frame 1 = 10101010 = 170, Frame 2 = 01000101 = 69, Frame 3 = 11001011 = 203, Frame 4 = 00101010 = 42. The protocol grants channel access in strictly descending order: Frame 3 (203) first, then Frame 1 (170), Frame 2 (69), and Frame 4 (42) last. This mirrors the binary countdown comparison: Frame 3 has the highest MSB pattern and survives all contention rounds first.
See Also
- Illustrating Working of Bit-Map Protocol with C++ Program — another contention-free MAC protocol using reservation slots
- Implementation of Hamming Code in C++ — error correction in transmitted frames
- Implementation of CRC Algorithm in C++ — error detection using polynomial division
- Implementation of Dijkstra Algorithm in C++ — shortest path routing algorithm
- Implementing Socket Programming in Java — TCP client-server communication
Conclusion
The Binary Countdown Protocol demonstrates how a deterministic, collision-free transmission order can be derived purely from each station’s binary address without any central coordinator. Its O(N) contention overhead makes it more efficient than random-access protocols under heavy load, though it inherently favours higher-addressed stations. Understanding this protocol provides a stepping stone to studying more sophisticated priority-based MAC schemes and the IEEE 802.1Q priority tagging used in modern Ethernet switches.