Combine 3 hexvalues by using left shift operator.
examples:
take decimal values as 2,129025,127 .combine the all hex values and need to come as 2,1F801,7F
Combine 3 hexvalues by using left shift operator.
examples:
take decimal values as 2,129025,127 .combine the all hex values and need to come as 2,1F801,7F
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
NaveenPosted Jan 22, 2024, 7:59 AM
i have used canwrite method in my post please use that in your answer.
NaveenPosted Jan 22, 2024, 7:53 AM
Hi jithu,
use canwrite method in your code please.
Jithu ThomasPosted Jan 22, 2024, 7:50 AM
@Naveen
please refer the updated the source code, now the output is just like as you needed.
Regards,
JITHU
NaveenPosted Jan 22, 2024, 7:47 AM
combine 3 hexvalues by using left shift operator.
examples:
take decimal values as 2,129025,127 .combine the all hex values and need to come as 2,1F801,7F
i need to write as 2,1F801,7F IN THE kvaser CANKING output.
What I have tried:
int h1=2;
int h2=129025;
int h3=127;
int combinedID = h1 + (h2<<8) + (h3<<25);
//for writing on kvaser canking
canlib.canwrite(handle,combinedID,data,data.length,0);
Jithu ThomasPosted Jan 22, 2024, 7:45 AM
using System;
class Program
{
static void Main()
{
// Decimal values
int value1 = 2;
int value2 = 129025;
int value3 = 127;
int combinedValue = (value1 << 20) | (value2 << 8) | value3;
string combinedHex = $"{value1},{combinedValue:X6},{value3:X2}";
Console.WriteLine(combinedHex);
}
}
Please accept the answer if you found the same is useful!