fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Reprezentacja_liczb_typu_float
  7. {
  8. class Program
  9. {
  10. static void printfloat(float x)
  11. {
  12. byte[] bytes = BitConverter.GetBytes(x);
  13. int i = BitConverter.ToInt32(bytes, 0);
  14.  
  15. string s = Regex.Replace(i.ToString("X"), ".{2}", "$0 "); ;
  16.  
  17. Console.WriteLine(RefactorHex(s));
  18. }
  19.  
  20. static void Main(string[] args)
  21. {
  22. int ile = int.Parse(Console.ReadLine());
  23.  
  24. List<float> wynikKoncowy = new List<float>();
  25. for (int i = 0; i < ile; i++)
  26. {
  27. wynikKoncowy.Add(float.Parse(Console.ReadLine().Replace(',', '.')));
  28. }
  29.  
  30. foreach (var item in wynikKoncowy)
  31. {
  32. printfloat(item);
  33. }
  34.  
  35. Console.ReadLine();
  36. }
  37.  
  38. private static string RefactorHex(string s)
  39. {
  40. string wynikKoncowy = "";
  41.  
  42. foreach (var item in s.Split(' '))
  43. {
  44. string b = item;
  45. if (item == "00")
  46. {
  47. b = "0";
  48. }
  49.  
  50. wynikKoncowy += b + " ";
  51.  
  52. }
  53.  
  54. if (s == "0")
  55. wynikKoncowy = "0 0 0 0";
  56. return wynikKoncowy.TrimEnd().ToLower();
  57. }
  58. }
  59. }
Success #stdin #stdout 0.03s 134592KB
stdin
5
1 
-1 
0 
123.125 
-345
stdout
3f 80 0 0
bf 80 0 0
0 0 0 0
42 f6 40 0
c3 ac 80 0