finding # of bits for irsend.

I am trying to make a program that will help me find any hidden codes/functions for devices like a radio tv etc.
my trouble is having my code figure out how many bits the signal is(does it even have to match? is this code even possible?).
my code so far.

//will help find ir commands for any device.
#include <IRremote.h>
#include <IRremoteInt.h>
//my global variables.
IRsend irsend;
const int next = 0//next button.
const int previous = 1;//previous button.
int signal = 0;//what it will send.
int low = 0;//parameters for faster searching.
int high = 0;
int rate = 5000;

void setup (){//enables serial and my buttons.
  pinMode(next, INPUT_PULLUP);
  pinMode(previous, INPUT_PULLUP);
  Serial.begin(9600);
}
int bits(){//used to calculate the # of bits the signal is. need help here.
  return (1);
}
void loop(){//my main loop.
  if (digitalRead(next) == HIGH){//if you press the next button.
    Serial.println("sending next command:");
    irsend.sendSony(signal, bits);                      and here.
    signal ++;
    delay (rate);
  }
  if (digitalRead(previous) == HIGH){//if you press the previous button.
    Serial.println("sending previous command:");
    irsend.sendSony(signal, 1);
    signal --;
    delay (rate);
  }   
}

The 'results' structure has a field "int bits;" as well as the "unsigned long value". I would dump the value and bits for all of the known buttons on your remote and look for patterns. Sort the captured codes by value to see if the 'bit' values clump together. When you capture codes be sure to note which order you pressed the keys so you can annotate the codes you find.

I had wanted the program cycle through the ir codes 12345,12346,12347,etc. and in order to send the codes it makes it needs the bits the codes are wich is a simple counting the number of 1's and 0's when its in binary for me but I dont know how I could do that in the program.

If you don't want to use existing codes as a pattern but rather try all of the billions of possible combinations of data value and length you can expect to be at it for much longer than 136 years (one code per second).