Click here to Skip to main content
15,905,071 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to make blood donation management system in C# windows forms? Pin
Pete O'Hanlon14-Dec-18 5:23
mvePete O'Hanlon14-Dec-18 5:23 
AnswerRe: How to make blood donation management system in C# windows forms? Pin
OriginalGriff14-Dec-18 5:44
mveOriginalGriff14-Dec-18 5:44 
AnswerRe: How to make blood donation management system in C# windows forms? Pin
Luc Pattyn14-Dec-18 6:50
sitebuilderLuc Pattyn14-Dec-18 6:50 
Question(might be solved) need some ideas about licensing implementation Pin
Super Lloyd11-Dec-18 21:01
Super Lloyd11-Dec-18 21:01 
AnswerRe: need some ideas about licensing implementation Pin
Mc_Topaz13-Dec-18 3:11
Mc_Topaz13-Dec-18 3:11 
AnswerRe: (might be solved) need some ideas about licensing implementation Pin
BillWoodruff13-Dec-18 9:21
professionalBillWoodruff13-Dec-18 9:21 
GeneralRe: (might be solved) need some ideas about licensing implementation Pin
Super Lloyd13-Dec-18 12:51
Super Lloyd13-Dec-18 12:51 
AnswerRe: (might be solved) need some ideas about licensing implementation Pin
GenJerDan13-Dec-18 19:43
GenJerDan13-Dec-18 19:43 
GeneralRe: (might be solved) need some ideas about licensing implementation Pin
Super Lloyd13-Dec-18 22:22
Super Lloyd13-Dec-18 22:22 
QuestionRegarding Audio Player Format Pin
Member 1408628311-Dec-18 19:27
Member 1408628311-Dec-18 19:27 
AnswerRe: Regarding Audio Player Format Pin
OriginalGriff11-Dec-18 20:14
mveOriginalGriff11-Dec-18 20:14 
GeneralRe: Regarding Audio Player Format Pin
Nelek13-Dec-18 20:41
protectorNelek13-Dec-18 20:41 
AnswerRe: Regarding Audio Player Format Pin
jschell15-Dec-18 7:03
jschell15-Dec-18 7:03 
AnswerRe: Regarding Audio Player Format Pin
mtoha15-Jan-19 15:32
professionalmtoha15-Jan-19 15:32 
QuestionDesign Form with DevComponent on C# Pin
Member 1408464310-Dec-18 15:16
Member 1408464310-Dec-18 15:16 
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 

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.