Description:
The formatToBinary(num) function will convert a given decimal number into its binary (base-2) representation.
Acceptance Criteria:
5 → "101"
10 → "1010"
255 → "11111111"
0 → "0"
Negative numbers should include a - prefix (e.g., -5 → "-101").
The function should accept an optional { group: n } parameter to group bits for readability.
Example: formatToBinary(255, { group: 4 }) → "1111 1111".
Input validation: throw an error for invalid or non-numeric inputs.
Add comprehensive unit tests for edge cases (e.g., 0, large numbers, and grouping).
Description:
The formatToBinary(num) function will convert a given decimal number into its binary (base-2) representation.
Acceptance Criteria:
Negative numbers should include a - prefix (e.g., -5 → "-101").
The function should accept an optional { group: n } parameter to group bits for readability.
Example: formatToBinary(255, { group: 4 }) → "1111 1111".
Input validation: throw an error for invalid or non-numeric inputs.
Add comprehensive unit tests for edge cases (e.g., 0, large numbers, and grouping).