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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
NaveenRank #6,081 · 277 reputationPosted Jan 22, 2024, 2:47 AM EST
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);
NaveenRank #6,081 · 277 reputationPosted Jan 22, 2024, 2:53 AM EST
Hi jithu,
use canwrite method in your code please.
NaveenRank #6,081 · 277 reputationPosted Jan 22, 2024, 2:59 AM EST
i have used canwrite method in my post please use that in your answer.
Jithu ThomasRank #437 · 5.7K reputationPosted Jan 22, 2024, 2:45 AM EST
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!
Jithu ThomasRank #437 · 5.7K reputationPosted Jan 22, 2024, 2:50 AM EST
@Naveen
please refer the updated the source code, now the output is just like as you needed.
Regards,
JITHU