I2C Address Frame Decoder
Try Change the 7-bit I2C device address from 0x76 to 0x77.
Observe Compare Write byte [A6…A0, 0] and Read byte [A6…A0, 1] for 0x77.
Explain Describe how adding 0 or 1 after the address bits produces the write byte or read byte.
Calculate
Reset
Technical boundaries. The decoder accepts only 7-bit addresses from 0x00 to 0x7F. It computes address bytes, marks reserved addresses, and supplies device labels from a fixed list.
viewof addr_hex = Inputs. text ({
label : "7-bit I2C device address (hex, e.g. 0x76)" ,
value : "0x76" ,
placeholder : "0x00 – 0x7F"
})
{
const raw = addr_hex. trim (). toLowerCase (). replace (/ ^ 0x/ , "" );
const addr = / ^[0-9a-f]{1,2}$ / . test (raw) ? parseInt (raw, 16 ) : NaN ;
if (isNaN (addr) || addr < 0 || addr > 127 ) {
return htl. html `<p style="color:#E74C3C">Enter a valid 7-bit address (0x00 to 0x7F)</p>` ;
}
const writeByte = (addr << 1 ) & 0xFF ;
const readByte = ((addr << 1 ) | 1 ) & 0xFF ;
const reserved = (addr <= 0x07 || addr >= 0x78 );
const bits = addr. toString (2 ). padStart (7 , "0" ). split ("" ). join (" " );
const known = {
0x3C : "OLED SSD1306" , 0x3D : "OLED SSD1306 (alt)" ,
0x76 : "BME280/BMP280" , 0x77 : "BME280/BMP280 (alt)" ,
0x68 : "MPU6050 / DS3231 RTC" , 0x69 : "MPU6050 (AD0=1)" ,
0x50 : "EEPROM 24Cxx" , 0x27 : "LCD I2C backpack" ,
0x3F : "LCD I2C backpack (alt)"
};
const knownLabel = known[addr] ? htl. html ` <span> - <em> ${ known[addr]} </em></span>` : "" ;
return htl. html `<div style="font-family:Arial,sans-serif;padding:12px;background:#f8f9fa;border-radius:6px;border:1px solid #dee2e6">
<table style="border-collapse:collapse;width:100%;font-size:0.9em">
<tr><th scope="col" style="text-align:left;padding:4px 8px">Address field</th><th scope="col" style="text-align:left;padding:4px 8px">Value</th></tr>
<tr><td style="padding:4px 8px;font-weight:bold">7-bit address</td>
<td style="padding:4px 8px;color:#2C3E50"><code>0x ${ addr. toString (16 ). toUpperCase (). padStart (2 , "0" )} </code> (decimal ${ addr} ) ${ knownLabel} </td></tr>
<tr><td style="padding:4px 8px;font-weight:bold">Binary bits [A6…A0]</td>
<td style="padding:4px 8px;font-family:monospace;color:#3498DB"> ${ bits} </td></tr>
<tr><td style="padding:4px 8px;font-weight:bold">Write byte [A6…A0, 0]</td>
<td style="padding:4px 8px;font-family:monospace;color:#16A085">
0x ${ writeByte. toString (16 ). toUpperCase (). padStart (2 , "0" )} = ${ writeByte. toString (2 ). padStart (8 , "0" ). split ("" ). join (" " )}
</td></tr>
<tr><td style="padding:4px 8px;font-weight:bold">Read byte [A6…A0, 1]</td>
<td style="padding:4px 8px;font-family:monospace;color:#E67E22">
0x ${ readByte. toString (16 ). toUpperCase (). padStart (2 , "0" )} = ${ readByte. toString (2 ). padStart (8 , "0" ). split ("" ). join (" " )}
</td></tr>
<tr><td style="padding:4px 8px;font-weight:bold">Reserved?</td>
<td style="padding:4px 8px;color: ${ reserved ? '#E74C3C' : '#16A085' } "> ${ reserved ? "Yes — do not use" : "No — available" } </td></tr>
</table>
</div>` ;
}
Back to the chapter