Embedded Number Converter
Convert numbers between hex, decimal, binary, and octal.
วิธีใช้งาน Embedded Number Converter
Embedded number converter แปลงค่าระหว่าง binary (ฐาน 2), octal (ฐาน 8), decimal (ฐาน 10) และ hexadecimal (ฐาน 16) พร้อมกำหนด bit width ได้ที่ 8, 16 หรือ 32 บิต แสดงค่า signed แบบ two's complement ตำแหน่ง bit แต่ละตำแหน่ง และการแบ่ง byte ทำให้เป็นเครื่องมือหลักสำหรับนักพัฒนา Embedded C ในการตรวจสอบค่า register ของ microcontroller ช่อง protocol packet และ flag แบบ bit-masked
ทุก ๆ หลัก hexadecimal แทน binary 4 บิตพอดี (nibble) ได้แก่ 0x0 = 0000, 0xA = 1010, 0xF = 1111 ทุก ๆ หลัก octal แทน binary 3 บิต ได้แก่ 0 = 000, 7 = 111 ทำให้ hex และ octal เป็นตัวย่อที่กระชับสำหรับค่า binary ส่วน decimal ไม่มีความสัมพันธ์ที่ชัดเจนกับ binary เช่น 0xFF = 255 ใน decimal ซึ่งต้องนับบิตเพื่อคำนวณในใจ converter ทำการแปลงทุกฐานได้ทันที
Embedded C ใช้ two's complement เพื่อแทน signed integer ในประเภท signed ขนาด 8 บิต 0xFF ไม่ใช่ 255 แต่คือ −1 และ 0x80 คือ −128 และ 0x7F คือ +127 การเข้าใจ two's complement จำเป็นอย่างยิ่งเมื่ออ่าน register status field, ADC reading ที่มี sign extension หรือค่า protocol แบบ serial ที่ใช้การคำนวณแบบ signed converter แสดงทั้งการตีความแบบ unsigned และ two's complement signed สำหรับทุก bit width
อุปกรณ์ต่อพ่วงของ microcontroller ใช้ bit field ภายใน register ขนาด 8, 16 หรือ 32 บิต มุมมอง bit layout แสดง bit แต่ละตำแหน่งที่มีหมายเลขตั้งแต่ MSB ถึง LSB ให้คุณระบุว่า bit ใดถูกตั้งค่าในค่า register โดยไม่ต้องคำนวณในใจ เช่น หากต้องการตรวจสอบว่า bit 5 ของ 0xAB ถูกตั้งค่าหรือไม่ 0xAB = 10101011 bit 5 คือ 1 (ถูกตั้งค่า) รูปแบบ C literal ได้แก่ prefix 0x สำหรับ hex, prefix 0b สำหรับ binary (GCC extension) และ prefix 0 สำหรับ octal แสดงควบคู่กับแต่ละการแทน
ใน Embedded C hexadecimal literal ใช้ prefix 0x เช่น uint8_t flags = 0xA5 Binary literal ใช้ 0b ใน GCC เช่น uint8_t flags = 0b10100101 Octal ใช้ตัวเลขนำหน้า 0 เช่น 0245 Type suffix มีความสำคัญ เช่น 0xFFFFFFFFU คือ unsigned และ 0xFFFFFFFFL คือ long Converter แสดง syntax C literal ที่ถูกต้องสำหรับค่าของคุณในทุกสี่ฐาน รวมถึง type suffix ที่เหมาะสมสำหรับค่า 16 บิตและ 32 บิต
คำถามที่พบบ่อย
- Why do embedded programmers use hex?
- Hexadecimal maps cleanly to binary: each hex digit represents exactly 4 bits (a nibble). This makes it easy to read bit patterns in registers, memory addresses, and protocol data.
- What is two's complement?
- Two's complement is the standard way to represent signed integers in binary. To negate a number: invert all bits and add 1. For an 8-bit signed integer, range is -128 to 127.
- What does 0xFF mean in 8-bit signed vs unsigned?
- In 8-bit unsigned, 0xFF = 255. In 8-bit signed (two's complement), 0xFF = -1. This converter shows both interpretations when you toggle the signed/unsigned mode.
เครื่องมือที่เกี่ยวข้อง
- Resistor Color Code Calculator
Decode resistor color bands. Supports 4-band and 5-band.
- Ohm's Law Calculator
Calculate voltage, current, resistance, or power using Ohm's Law.
- Voltage Divider Calculator
Calculate output voltage for a resistor voltage divider.
- 555 Timer Calculator
Calculate frequency, duty cycle, and timing for 555 timer circuits.
- CRC Calculator
Calculate CRC checksums — CRC-8, CRC-16, CRC-32, and custom polynomials.