Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
AnswerRe: Design Form with DevComponent on C# Pin
OriginalGriff10-Dec-18 20:06
mveOriginalGriff10-Dec-18 20:06 
AnswerRe: Design Form with DevComponent on C# Pin
BillWoodruff11-Dec-18 5:35
professionalBillWoodruff11-Dec-18 5:35 
PraiseRe: Design Form with DevComponent on C# Pin
Eddy Vluggen11-Dec-18 6:18
professionalEddy Vluggen11-Dec-18 6:18 
QuestionK-means clustering algorithm in C# Pin
Member 1408268110-Dec-18 10:42
Member 1408268110-Dec-18 10:42 
AnswerRe: K-means clustering algorithm in C# Pin
OriginalGriff10-Dec-18 20:05
mveOriginalGriff10-Dec-18 20:05 
GeneralRe: K-means clustering algorithm in C# Pin
Member 1408268110-Dec-18 20:08
Member 1408268110-Dec-18 20:08 
GeneralRe: K-means clustering algorithm in C# Pin
OriginalGriff10-Dec-18 20:21
mveOriginalGriff10-Dec-18 20:21 
QuestionBitConverter.ToString with customizable length? Pin
Nelek10-Dec-18 2:46
protectorNelek10-Dec-18 2:46 
Hi guys,

I am working in something new and I would like to write a binary file with fields of different length, being it 2, 4, 8 bytes mostly.

I already get the desired conversion for doubles with
C#
double dTest_max = 15.020245207;
byte[] bytesDouble_max = BitConverter.GetBytes(dTest_max);
Console.WriteLine("Hexa Double MAX (byte[]) = 0x" + BitConverter.ToString(bytesDouble_max).Replace("-", ""));

//output = 0x95D626E80B2E113E

Using the same with the integer "312" gives me: output = 0x38010000

If I cast the int to long I do get my desired: output = 0x380100000000

But as the desired length of the parameter in the binary telegram is fixed by header (dynamic) I would like to avoid having to evaluate the respective length of the actual parameter to choose if I have to cast it or not.

Is there any hidden function / method in .Net that could do that?
I mean something like:
C#
Console.WriteLine("0x"+int.ToString("X")); //gives 0x138
Console.WriteLine("0x"+int.ToString("X12")); //gives 0x138000000000

But for the BitConverter?


I have already had a look to: BitConverter Class (System) | Microsoft Docs[^] and its overloads, but the "start" and "length" are only to be used if the data input is an array, and haven't seen anything to determine the length of the output


If not... I am already thinking to use workarounds like filling bytes[] with different fixed lengths and then replacing only the bytes given by the conversion.

Using int.ToString("X12") and the "reversing" it would do the job too, but I am not sure if that would be reliable enough for my use case.
M.D.V. Wink | ;)

If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.

AnswerRe: BitConverter.ToString with customizable length? Pin
OriginalGriff10-Dec-18 4:06
mveOriginalGriff10-Dec-18 4:06 
GeneralRe: BitConverter.ToString with customizable length? Pin
Nelek10-Dec-18 21:18
protectorNelek10-Dec-18 21:18 
GeneralRe: BitConverter.ToString with customizable length? Pin
OriginalGriff10-Dec-18 21:30
mveOriginalGriff10-Dec-18 21:30 
GeneralRe: BitConverter.ToString with customizable length? Pin
Nelek10-Dec-18 21:46
protectorNelek10-Dec-18 21:46 
GeneralRe: BitConverter.ToString with customizable length? Pin
OriginalGriff10-Dec-18 22:02
mveOriginalGriff10-Dec-18 22:02 
GeneralRe: BitConverter.ToString with customizable length? Pin
Nelek11-Dec-18 2:59
protectorNelek11-Dec-18 2:59 
GeneralRe: BitConverter.ToString with customizable length? Pin
BillWoodruff13-Dec-18 9:25
professionalBillWoodruff13-Dec-18 9:25 
QuestionCode in c# Pin
Mody_20048-Dec-18 4:07
Mody_20048-Dec-18 4:07 
AnswerRe: Code in c# Pin
OriginalGriff8-Dec-18 4:23
mveOriginalGriff8-Dec-18 4:23 
AnswerRe: Code in c# Pin
Eddy Vluggen8-Dec-18 5:11
professionalEddy Vluggen8-Dec-18 5:11 
AnswerRe: Code in c# Pin
Dave Kreskowiak9-Dec-18 5:13
mveDave Kreskowiak9-Dec-18 5:13 
AnswerRe: Code in c# Pin
Kevin Marois10-Dec-18 8:07
professionalKevin Marois10-Dec-18 8:07 
Questionhow to bind all text filed with dropdownlist data selection in kendo grid,give any example Pin
Member 115679596-Dec-18 1:25
Member 115679596-Dec-18 1:25 
AnswerRe: how to bind all text filed with dropdownlist data selection in kendo grid,give any example Pin
OriginalGriff6-Dec-18 2:35
mveOriginalGriff6-Dec-18 2:35 
GeneralRe: how to bind all text filed with dropdownlist data selection in kendo grid,give any example Pin
Richard Andrew x648-Dec-18 5:32
professionalRichard Andrew x648-Dec-18 5:32 
QuestionThere is already an open DataReader associated with this Command which must be closed first. Pin
govind_nanna5-Dec-18 19:45
govind_nanna5-Dec-18 19:45 
AnswerRe: There is already an open DataReader associated with this Command which must be closed first. Pin
Pete O'Hanlon5-Dec-18 20:54
mvePete O'Hanlon5-Dec-18 20:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.