1 / 36 · Khái niệm
Binary and hexadecimal
Represent the same value in binary and hexadecimal.
Bài học miễn phí. Đăng ký để lưu tiến độ học tập.
Chưa có bản dịch. Nội dung bài học gốc được hiển thị. (English)
Learning goals
- Calculate a binary value from its place weights.
- Map groups of four bits to hexadecimal digits.
Each bit position has a weight.
The unsigned value of b[3:0] is 8×b[3] + 4×b[2] + 2×b[1] + b[0]. Thus 1010 is 10 and 0010 is 2. Leading zeros preserve the value but affect the declared width.
An N-bit unsigned value ranges from 0 to 2^N−1. The value 16 needs five bits. A four-bit destination can discard the high bit, so choose the required range first.
Hexadecimal is a compact notation for bits.
Group bits in fours from the right. 1010 is A and 1111 is F, so 1010_1111 is AF in hexadecimal. The notation changes; the stored bits do not.
In SystemVerilog, 8'hAF and 8'b1010_1111 have the same value and width. The number before the apostrophe specifies the bit width, not the base.
| Binary | Hex | Decimal |
|---|---|---|
| 0000 | 0 | 0 |
| 0111 | 7 | 7 |
| 1000 | 8 | 8 |
| 1111 | F | 15 |
Tự thử
Convert 0011_1100 to hexadecimal and decimal.
Đọc giải thích
0011 is 3 and 1100 is C, giving 0x3C. The weighted sum is 32+16+8+4=60.