Hi Guys,
I have wrote a small logic below which will calculate a value called MASK via which I can calculate the starting and ending number
This logic works fine if A = 0x14000000 B = 0x14000064

void main()
{
    unsigned long ulStartVal = 0x14000000;
    unsigned long ulEndVal = 0x14000064;
    unsigned long ulMask;
    unsigned long ulTempVal;
    // Calculate mask
    ulMask = ~((ulStartVal) ^ (ulEndVal));
    /* This step is kindoff mandatory startval AND operation with mask must give 
    the value of startval again (value of ulTempVal and ulStartVal must be same) */
    ulTempVal = ulStartVal & ulMask;
    printf("%x %x",ulTempVal, ulMask);
    //Endval calculation with startval and mask
    ulEndVal  = ~((ulTempVal) ^ (ulMask));
    printf("%x",ulEndVal);
}

But the above logic doesn't work fine if A = 0x1400000A B = 0x14000064 means if the value of A has last 8 bits set. C code or pseudo code or any suggestion on logic change is very much welcome.

Why are you over-writing ulEndVal near the end? What values are you getting vs. what values are you expecting? How does it not work? On line 11, do you want to use ulStartVal or ulEndVal?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.