Autocoder

Texas Instruments Coding Round Questions with Solutions

Last updated 2026-11-19

Written tests for embedded roles usually ask for short C functions on bits, buffers and protocols rather than long algorithm puzzles: reverse the bits of a byte, compute a checksum, implement a ring buffer, convert Gray code. This page gives twelve problems in that style, each with a complete C solution, its complexity and the usual mistake.

They are practice problems in the style of topics such tests are commonly reported to include, not real papers. For concept questions see Texas Instruments interview questions, and for more bit work see bit manipulation interview questions.

Habits that score well

Use fixed-width types from stdint.h, unsigned for bit work, and parentheses around every bit expression. Say what happens for the empty or full buffer and for the all-zero input. In embedded code, the interviewer reads those habits as carefulness.

Where a problem mentions an interrupt, mark shared variables volatile and keep the critical section short.

Hiring status

No sourced hiring facts for Texas Instruments are held on this site, so no dates, openings or packages are quoted. Use the company's own careers site for current information.

Texas Instruments Coding Round Questions with Solutions: questions with worked answers

  1. 1

    Write macros to set, clear, toggle and test bit n of a register.

    easy

    Use a mask of 1u shifted by n. Set with OR, clear with AND of the inverted mask, toggle with XOR, and test with AND. Time O(1). Common mistake: writing 1 << n with a signed int when n can be 31, which is undefined, and forgetting parentheses around the macro argument.

    c
    #include <stdio.h>
    #include <stdint.h>
    #define BIT(n)        (1u << (n))
    #define SET(r, n)     ((r) |= BIT(n))
    #define CLEAR(r, n)   ((r) &= ~BIT(n))
    #define TOGGLE(r, n)  ((r) ^= BIT(n))
    #define TEST(r, n)    (((r) >> (n)) & 1u)
    int main(void) {
        uint8_t r = 0;
        SET(r, 3); SET(r, 0); TOGGLE(r, 0); CLEAR(r, 5);
        printf("0x%02X %u\n", r, TEST(r, 3)); /* 0x08 1 */
        return 0;
    }
  2. 2

    Predict the output: 8-bit arithmetic that wraps.

    easy

    x is an unsigned char holding 200. In x + 100 the operands are promoted to int, so the value is 300. Storing it back with x += 100 truncates to 8 bits: 300 - 256 = 44. Output: 300 44. Common mistake: forgetting integer promotion, or assuming unsigned char arithmetic is done in 8 bits.

    c
    #include <stdio.h>
    int main(void) {
        unsigned char x = 200;
        printf("%d ", x + 100);
        x += 100;
        printf("%d\n", x);
        return 0;
    }
  3. 3

    Implement a fixed-size ring buffer with push and pop.

    medium

    Keep head and tail indices and a capacity N. Push writes at head and advances it modulo N unless the next head equals tail, which means full; pop reads from tail unless head equals tail, which means empty. This design wastes one slot but needs no count, which makes single-producer, single-consumer use safe without locks. Time O(1) per operation, space O(N). Common mistake: using head == tail for both empty and full.

    c
    #include <stdio.h>
    #define N 4
    typedef struct { int d[N]; int head, tail; } Ring;
    int push(Ring *r, int v) {
        int nx = (r->head + 1) % N;
        if (nx == r->tail) return 0;
        r->d[r->head] = v; r->head = nx; return 1;
    }
    int pop(Ring *r, int *v) {
        if (r->head == r->tail) return 0;
        *v = r->d[r->tail]; r->tail = (r->tail + 1) % N; return 1;
    }
    int main(void) {
        Ring r = {{0}, 0, 0};
        int ok = 0, v;
        for (int i = 1; i <= 5; i++) ok += push(&r, i);
        pop(&r, &v);
        printf("%d %d\n", ok, v); /* 3 1 */
        return 0;
    }
  4. 4

    Reverse the bits of a byte. Where is this used?

    medium

    Loop eight times, shifting the result left and taking the lowest bit of the input each time. 0x01 becomes 0x80 and 0x0B (00001011) becomes 0xD0 (11010000). Time O(8) = O(1). A 256-entry lookup table trades 256 bytes for one load. It appears in bit-reversed addressing for FFTs and in serial protocols that send the most significant bit first.

    c
    #include <stdio.h>
    #include <stdint.h>
    uint8_t rev8(uint8_t x) {
        uint8_t r = 0;
        for (int i = 0; i < 8; i++) { r = (uint8_t)((r << 1) | (x & 1u)); x >>= 1; }
        return r;
    }
    int main(void) {
        printf("0x%02X 0x%02X\n", rev8(0x01), rev8(0x0B)); /* 0x80 0xD0 */
        return 0;
    }
  5. 5

    Compute a CRC-8 (polynomial 0x07) over a byte buffer.

    medium

    Start with 0, XOR each byte into the register, then for each of eight bits shift left and, if the top bit was set before the shift, XOR with the polynomial. For the ASCII string 123456789 this CRC-8 gives 0xF4, a common check value. Time O(8n), space O(1); a table cuts it to O(n). Common mistake: testing the top bit after the shift instead of before.

    c
    #include <stdio.h>
    #include <stdint.h>
    #include <string.h>
    uint8_t crc8(const uint8_t *p, size_t n) {
        uint8_t crc = 0;
        while (n--) {
            crc ^= *p++;
            for (int i = 0; i < 8; i++)
                crc = (crc & 0x80u) ? (uint8_t)((crc << 1) ^ 0x07u) : (uint8_t)(crc << 1);
        }
        return crc;
    }
    int main(void) {
        const char *s = "123456789";
        printf("0x%02X\n", crc8((const uint8_t *)s, strlen(s))); /* 0xF4 */
        return 0;
    }
  6. 6

    Compute the parity of a byte.

    easy

    XOR-fold the byte onto itself: x ^= x >> 4, x ^= x >> 2, x ^= x >> 1, then the lowest bit is 1 for an odd number of set bits. 0xB3 has five set bits, so parity is 1. Time O(1). Common mistake: counting bits in a loop when a fold is expected, or returning the whole folded byte instead of its lowest bit.

    c
    #include <stdio.h>
    #include <stdint.h>
    int parity(uint8_t x) {
        x ^= x >> 4; x ^= x >> 2; x ^= x >> 1;
        return x & 1;
    }
    int main(void) {
        printf("%d %d\n", parity(0xB3), parity(0x03)); /* 1 0 */
        return 0;
    }
  7. 7

    Convert between binary and Gray code.

    medium

    Gray code changes only one bit between consecutive values. Binary to Gray is g = b ^ (b >> 1). Gray to binary XORs every higher bit in: b = g; then b ^= b >> 1, b ^= b >> 2, and so on. Binary 5 (101) becomes Gray 7 (111). Time O(log w). Gray code is used in rotary encoders so a transition never reads a wildly wrong value.

    c
    #include <stdio.h>
    #include <stdint.h>
    uint8_t to_gray(uint8_t b) { return b ^ (b >> 1); }
    uint8_t from_gray(uint8_t g) {
        g ^= g >> 1; g ^= g >> 2; g ^= g >> 4;
        return g;
    }
    int main(void) {
        printf("%u %u\n", to_gray(5), from_gray(7)); /* 7 5 */
        return 0;
    }
  8. 8

    Implement a moving average over the last N samples with O(1) work per sample.

    medium

    Keep a circular buffer of the last N samples and a running sum. For each new sample, subtract the oldest value, add the new one, store it and advance the index. The average is sum / N once the buffer has filled. Time O(1) per sample, space O(N). Use a wider type for the sum so it cannot overflow. Common mistake: recomputing the whole sum every time, which is O(N).

    c
    #include <stdio.h>
    #include <stdint.h>
    #define N 4
    int main(void) {
        int16_t in[] = {10, 20, 30, 40, 50, 60};
        int16_t win[N] = {0};
        int32_t sum = 0;
        int idx = 0;
        for (int i = 0; i < 6; i++) {
            sum -= win[idx];
            win[idx] = in[i];
            sum += in[i];
            idx = (idx + 1) % N;
            if (i >= N - 1) printf("%d ", sum / N);
        }
        puts("");  /* 25 35 45 */
        return 0;
    }
  9. 9

    Add two Q15 numbers with saturation.

    medium

    Add as 32-bit integers, then clamp to the range -32768 to 32767 instead of letting the 16-bit sum wrap around, which would flip a large positive result to a negative one. Time O(1). Saturation is the standard behaviour in DSP code because a clipped signal sounds better than a wrapped one. Common mistake: adding in int16_t, where the overflow is implementation-defined on conversion.

    c
    #include <stdio.h>
    #include <stdint.h>
    int16_t sat_add(int16_t a, int16_t b) {
        int32_t s = (int32_t)a + b;
        if (s > 32767) return 32767;
        if (s < -32768) return -32768;
        return (int16_t)s;
    }
    int main(void) {
        printf("%d %d %d\n", sat_add(30000, 5000), sat_add(-30000, -5000), sat_add(100, 200));
        /* 32767 -32768 300 */
        return 0;
    }
  10. 10

    Assemble a 32-bit value from four bytes received in big-endian order.

    easy

    The first byte is the most significant. Shift each byte into place and OR them: (b0 << 24) | (b1 << 16) | (b2 << 8) | b3. Cast b0 to uint32_t before shifting, otherwise the byte is promoted to a signed int and shifting a value of 128 or more into bit 31 is undefined. Bytes 0x12 0x34 0x56 0x78 give 0x12345678. Time O(1). This is portable across endianness, unlike casting a char pointer to a uint32_t pointer.

    c
    #include <stdio.h>
    #include <stdint.h>
    uint32_t be32(const uint8_t *p) {
        return ((uint32_t)p[0] << 24) | ((uint32_t)p[1] << 16) | ((uint32_t)p[2] << 8) | p[3];
    }
    int main(void) {
        const uint8_t b[] = {0x12, 0x34, 0x56, 0x78};
        printf("0x%08X\n", be32(b)); /* 0x12345678 */
        return 0;
    }
  11. 11

    Predict the output: sizeof an array, a pointer to a string literal, and strlen.

    medium

    s is a char array initialised from "ab", holding 3 bytes including the terminating zero, so sizeof(s) is 3. t is a pointer, so sizeof(t) is the pointer size, 8 on a 64-bit platform. strlen counts characters before the terminator, so it is 2. Output on a 64-bit machine: 3 8 2. Common mistake: expecting sizeof of a pointer to give the string length. On a 16-bit microcontroller the pointer size would be 2.

    c
    #include <stdio.h>
    #include <string.h>
    int main(void) {
        char s[] = "ab";
        const char *t = "ab";
        printf("%zu %zu %zu\n", sizeof(s), sizeof(t), strlen(t));
        return 0;
    }
  12. 12

    Debounce a button in software with an integrating counter. Show the state machine on a sample stream.

    hard

    Sample the pin every tick. Increment a counter while the input reads high and decrement while it reads low, clamped between 0 and a limit, and change the output to high only when the counter reaches the limit and to low only when it reaches 0. This ignores short glitches and needs only one byte of state. Time O(1) per sample. Common mistake: acting on the first edge and so reacting to bounce.

    c
    #include <stdio.h>
    #define LIMIT 3
    int main(void) {
        int samples[] = {0,1,0,1,1,1,1,0,1,0,0,0,0};
        int cnt = 0, out = 0;
        for (int i = 0; i < 13; i++) {
            if (samples[i]) { if (cnt < LIMIT) cnt++; } else { if (cnt > 0) cnt--; }
            if (cnt == LIMIT) out = 1;
            else if (cnt == 0) out = 0;
            printf("%d", out);
        }
        puts("");  /* 0000011111100 */
        return 0;
    }

Frequently asked questions

What kind of coding questions suit an embedded firmware test?

Commonly reported are bit manipulation, buffers, checksums, state machines, fixed-point arithmetic and C output prediction. They test careful use of types and edge cases more than advanced algorithms.

Should I write C or C++ in an embedded test?

Use C unless the test says otherwise, with stdint.h types. Many embedded toolchains and code standards are C first.

Are these real TI test questions?

No. They are practice problems in the style of topics such tests are commonly reported to cover. The company does not publish its papers.

How do I practise without hardware?

Compile and run the functions on your PC with test inputs, as every problem here does. Then try one on a development board, using a UART to print results.

Related guides

More in Company Interview Questions

See all in this section