Skip to content

Formatting: Add formatToBinary function #125

Description

@Farkhanda-Dalal

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).

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions