anshchawla:
See I am new to. Arduino so I didn't understand what you meant
Basically I want to store an IR code recorded using an IR receiver into an array
But the IR code is in hex form
Eg one of the codes is 95D6DEA1
But an error occurs if I try to store this hex value in array
Let us review few concepts before going to save your IR data (95D6DEA1) in an array.
1. The basic data size is 8-bit, and it is known as byte.
2. In computer/microcontroller memory, data is always stored in bit form like: 10010101. Let us designate these bits as bit-0 (the right most one as we are face the pattern), b-t1, ..., bit-7 (bo, b1, ..., b7). What is the decimal value of it? This is an area of another business -- we will not go there now.
3. Let us give a symbolic name x to the bit pattern of Step-2. Now, we have: x = 10010101.
4. If I ask you to write the value of x on a piece of paper, you will write 10010101. Correct!
5. In Step-4, you have written 8 symbols (10010101). Is it not a cumbersome job of writing so many symbols/digits? There is also a chance of error as a bit appear may be written as 0; whereas, it should be 1. Is there any better way of writing the value if x, which will reduce this endurance. Yes, there is the following way/method:
(1) Take 4-bit block from the left; now, we have two blocks: 1001 and 0101. Get the value of these blocks in base 2 (binary base); now, we have this value for the 1st block (from left): 1x23 + 0x22 + 0x20 + 1x20 = 8 + 0 + 0 + 1 =9.
(2) Similarly, the 2nd block 0101 will end up with : 5. Now we have: 95 in place of 10010101. Are they different? No! They are not different -- they are the same. The 2nd form (95) is known as hexadecimal (hex) representation of 10010101, and we do it as a matter of convenience. The actual processing is done on the bit pattern (10010101) and not on hex form (95).
6. In your data stream (95D6DEA1), you have 4-byte data. Let us assume that they are binary codes (and they are in binary form and not ASCII codes). Let us store them in an array in the following way:
byte nyData[4] = {0x95, 0xD6, 0xDE, 0xA1};
//0x is appended to mean that the digits following 0x is in hex form;
//so, before processing they must be converted into bit form like:
//95---> 10010101, D6--->11010110, and etc.
Hope that you have got the points.