0

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.

2
Contributors
1
Reply
16
Views
2 Years
Discussion Span
Last Post by Nutster
0

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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.