Number base converter: show what a hex or binary bit pattern means as a signed integer (`0xFFFFFFFF` is -1 in 32 bits)

Đang mở
#494 2 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@bhushan4work đang làm issue này rồi.

Từ ngày 27/11/2026.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
82/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
nextjs, react, typescript
Lĩnh vực
frontend

Hướng nghiên cứu

Start by reading fromTwosComplement and formatInteger in lib/number-base.ts and the tests covering them in lib/__tests__/number-base.test.ts (lines 124-145), then look at the twos memo and the two's complement column in NumberBaseConverterClient.tsx. Add the new output card so it renders even when the "doesn't fit" error does, and add the FAQ sentence in lib/tools.ts around line 512. Write NumberBaseConverterClient.test.tsx modelled on UuidGeneratorClient.test.tsx; done means the four hex cases show the signed values, 0x1FF at 8 bits and -5 show the placeholder, and lint, test and build pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

enhancement good first issue

The two's complement part only works in one direction. Type -1 with 8-bit selected and you get 11111111. The question people more often have goes the other way: they have a register value, an error code or a hex dump and want to know what it is as a signed integer. Type 0xFFFFFFFF with 32-bit selected and the tool says "4294967295 doesn't fit in a signed 32-bit integer (-2147483648 to 2147483647)" and shows nothing else. 0x80 at 8 bits and 0x80070005 (a Windows HRESULT) at 32 bits do the same.

The logic for this is already written and tested. fromTwosComplement (lib/number-base.ts, line 132) reads binary digits as a signed value of a given width, and lib/__tests__/number-base.test.ts covers it (lines 124 to 145). Nothing in the UI calls it.

What to do

  • Add an output card to the two's complement column, for example "As a signed 32-bit value", that reads the input as a bit pattern of the chosen width: fromTwosComplement(formatInteger(value, 2), bits). Show it for values from 0 to 2^bits - 1. For a negative input, or one wider than the width, show a short placeholder that says why it's empty.
  • It has to show even when the "doesn't fit" error does, since that's the case it's for. Today the error replaces the whole column (NumberBaseConverterClient.tsx, lines 269 to 286).
  • Add a sentence about it to the "How does two's complement work here?" FAQ in lib/tools.ts (line 512).

Where to look

  • app/(tools)/number-base-converter/NumberBaseConverterClient.tsx: the twos memo (line 91) and the two's complement column (lines 251 to 287)
  • lib/number-base.ts: formatInteger (line 95) and fromTwosComplement (line 132)
  • The converter has no component test yet. Add NumberBaseConverterClient.test.tsx next to it. app/(tools)/uuid-generator/UuidGeneratorClient.test.tsx is a good model.

Acceptance criteria

  • 0xFFFFFFFF at 32 bits shows -1, 0x80 at 8 bits shows -128, 0x7F at 8 bits shows 127, and 0x80070005 at 32 bits shows -2147024891
  • 0x1FF at 8 bits and -5 show the placeholder, not a number
  • The existing outputs and errors don't change
  • Tests that fail on the current code
  • npm run lint, npm run test and npm run build pass

How to test

In the component test, type into the field labelled "Number", pick the width from "Two's complement width", and check the new card's text for each case above. By hand: npm run dev, open /number-base-converter, enter 0xFFFFFFFF and switch between 8, 16, 32 and 64 bits.


Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off develop, and open your PR against develop with Closes #494 in the description.

Ngôn ngữ chính
TypeScript
Star
1
Fork
9
Merge trung bình
1 ngày 8 giờ
Pull request đã merge (30 ngày)
49

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của codercops/toolbelt

Tất cả issue của codercops/toolbelt

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.