Explaining c++ code

Can anyone explain this code below:
00027 class NodeId
00028 {
00034 public:
00035
00039 NodeId(t_uint numericValue)
00040 : m_numericValue(numericValue)
00041 { }
00042
00051 NodeId(const t_uchar* byteArray, t_uint byteCount)
00052 {
00053 m_numericValue = 0;
00054 for(t_uint i = 0; i < byteCount; i++) {
00055 if(i > sizeof(t_uint))
00056 assert(byteArray[i] == 0);
00057 m_numericValue += (byteArray[i] << (8 * i));
00058 }
00059 }
First use code tags
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class NodeId
{
public:

    NodeId(t_uint numericValue)
    : m_numericValue(numericValue)
    { }

    NodeId(const t_uchar* byteArray, t_uint byteCount)
    {
        m_numericValue = 0;
        for(t_uint i = 0; i < byteCount; i++)
        {
            if(i > sizeof(t_uint))
            {
                assert(byteArray[i] == 0);
            }
            m_numericValue += (byteArray[i] << (8 * i));
        }
    }
};

Second ask c++ related question in Beginner/General C++ Boards.
And try to give as much information you can for the problem.
Please see this:
http://www.cplusplus.com/forum/beginner/1/

What exactly can't you understand , is it the bit shifting ?
http://stackoverflow.com/questions/141525/absolute-beginners-guide-to-bit-shifting
(Remember that C++ does not have >>> operator and >> for negative numbers is implementation defined.)
Last edited on
Sorry for posting here, and next time I will post int the proper section. This code from a simulator called RFIDSIM on which I am trying to run an experiment. I want to know what these function called, so I can start learning them. For example, is the NodeId(t_uint numericValue) constructor?

Thanks for the reply
Yeah,both if 'em are constructors ...
The first initualizes m_numericValue with the one provided.
The second constructor initialises m_numericValue with an array of bytes , all concatenated(ini binary) in reverse order to single number.
So for example the size of int on most systems is 4 bytes , so when you pass an array of bytes (with the assertion if the no. of byes passed > 4 then those extra bytes must be 0s)
Let the bytes passed be 0xff,0x0a,0x01 so m_numericValue will be initialized as 0x00010aff. (Stored in little endian format)
I

Are you totally new to c++ ? If so then you can learn it from the tutorial on this site.

Hope that helps.
Last edited on
Thank you very much a k n. This helps me a lot
Topic archived. No new replies allowed.