Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7541915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:01:10+00:00 2026-05-30T08:01:10+00:00

I have to create an unsigned int array to make an IR remote message.

  • 0

I have to create an unsigned int array to make an IR remote message. To do this, I have to concatenate the header to the data bits, depending of which key I want to mimic.
Here’s what I have and the problem:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const unsigned HEADER[34] = {4608, 4398, 655, 1588, 655, 1588, 655, 1588, 655, 472, 655, 472, 655, 472, 655, 472, 655, 472, 655, 1588, 655, 1588, 655, 1588, 655, 472, 655, 472, 655, 472, 655, 472, 655, 472};

unsigned short BTN_VOL_UP = 0xE01F;

void intToBin(unsigned short a, char* buffer) {
    buffer += 15;
    int i = 15;
    for (i; i >= 0; i--) {
        *buffer-- = (a & 1) + '0';
        a >>= 1;
    }
}

void hexToData(unsigned** data, int code) {
  char* strHex = (char*) malloc(16 * sizeof(char));
  intToBin(code, strHex);
  int i = 0;
  for(i; i < 16; i++) {
    char c = strHex[i];
    *(*data)++ = 655;
    if (c == '1') {
      *(*data)++ = 1588;
    } else {
      *(*data)++ = 472;
    }
  }
  (*data) -= 32;
}

void getCode(unsigned** data, short code) {
  int i = 0;
  for (i; i < 34; i++) {
    *(*data)++ = HEADER[i];
  }
  unsigned* bits = (unsigned*) malloc(32 * sizeof(unsigned));
  hexToData(&bits, code);
  i = 0;
  for (i; i < 32; i++) {
    *(*data)++ = bits[i];
  }
  *(*data)++ = 647;
  *(*data)++ = 0;
  (*data) -= 68;
}

And here’s the code calling all this:

unsigned* data = (unsigned*) calloc(68, sizeof(unsigned));
getCode(&data, BTN_VOL_UP);

After that, I print the HEADER (using a for to print each value) and the data variable, but that’s what I get:

4608 4398 655 1588 655 1588 655 1588 655 472 655 472 655 472 655 472 655 472 655 1588 655 1588 655 1588 655 472 655 472 655 472 655 472 655 472

0 136 1588 655 1588 655 1588 655 472 655 472 655 472 655 472 655 55298 36609 55298 36609 55298 36609 55298 36609 55298 36609 55298 36609 55298 36609 55298 36609 655 655 1588 655 1588 655 1588 655 472 655 472 655 472 655 472 655 472 655 472 655 472 655 472 655 1588 655 1588 655 1588 655 1588 655 1588 647 0 16

The HEADER is correct, but the data is all messed up: the header in the data is completely wrong, the actually data part (the VOL_UP code) is right, but there’s an extra value on the end that shouldn’t be there: 16. the array should end with …647, 0}.

Any ideas what’s wrong with the code?

EDIT: I found the problem, edited the code to include corrections.
Turns out that I was having problem finding the exact location to copy the values, so I decided to manually copy int by int and subtract the pointer at the end. Ugly, but it works.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:01:11+00:00Added an answer on May 30, 2026 at 8:01 am

    Your code produces following…

    4608 4398 655 1588 655 1588 655 1588 655 472 655 472 655 472 655 472 655 472 655 1588 655 1588 655 1588 655 472 655 472 655 472 655 472 655 472 1588 1588 1588 655 655 655 655 655 655 655 655 1588 1588 1588 1588 1588 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 647 0
    

    Seems header is ok. I don’t know algorithm for key generation, so I can’t tell you if values 34-49 are ok, but you definitely have problem in 50-65 range. Your code never sets them to any value. Usually malloc doesn’t initalize memory (it depends on standard library implementation tho), so you will get garbage in 50-65.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this table CREATE TABLE `codes` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
I have a members table in MySQL CREATE TABLE `members` ( `id` int(10) unsigned
I have a MySQL table consisting of: CREATE TABLE `url_list` ( `id` int(10) unsigned
I have a table, | PAGELETS | CREATE TABLE `PAGELETS` ( `page_key` int(32) unsigned
I have a vector of doubles and I need to create another array which
The table is currently this: CREATE TABLE `feed_items` ( `id` int(11) unsigned NOT NULL
I have the following mysql tables: CREATE TABLE `video` ( `video_id` int(11) unsigned NOT
I have 2 tables: CREATE TABLE `product_det` ( `id` bigint(12) unsigned NOT NULL AUTO_INCREMENT,
I have the following table schema; CREATE TABLE `db1`.`sms_queue` ( `Id` INTEGER UNSIGNED NOT
I have create my own NSOpenGLView class, right now the data that i want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.