From: tonyg on 19 Apr 2010 11:44 I have some data coming in from a serial port which I want to convert to hexadecimal and display on the screen. I was wondering if anyone knows of a simple way to do this?
From: tonyg on 19 Apr 2010 11:58 On Apr 19, 4:44 pm, tonyg <tonytheg...(a)googlemail.com> wrote: > I have some data coming in from a serial port which I want to convert > to hexadecimal and display on the screen. I was wondering if anyone > knows of a simple way to do this? To make myself more clear I have already dealt with the serial comms bit, I am looking to display the stream I have already captured
From: Warren on 20 Apr 2010 11:52 J-P. Rosen expounded in news:hqkeo7$p8r$1(a)news.eternal-september.org: > Warren a �crit : > >> I guess it helps not to have preconceptions when looking >> for stuff. I looked for a "white" jar of mayonnaise and of >> course couldn't find it. This was because my wife bought >> mayonnaise in a yellow plastic jar (recently), which I >> mistook for mustard. She of course, had no trouble at >> all finding it. >> > Now, you understand the importance of having unambiguous specifications > that match the implementation (back on topic) ;-) Indeed! with Fridge.Mayonnaise; Warren
From: Ludovic Brenta on 19 Apr 2010 12:24 tonyg wrote on comp.lang.ada: > On Apr 19, 4:44 pm, tonyg <tonytheg...(a)googlemail.com> wrote: > > > I have some data coming in from a serial port which I want to convert > > to hexadecimal and display on the screen. I was wondering if anyone > > knows of a simple way to do this? > > To make myself more clear I have already dealt with the serial comms > bit, I am looking to display the stream I have already captured You could use the predefined library to get a result using the Ada "syntax for based literal" (ARM A.10.8(14)), e.g. 16#CE#. package Stream_Element_IO is new Ada.Text_IO.Modular_IO (Num => Ada.Streams.Stream_Element); E : Ada.Streams.Stream_Element := ... begin Stream_Element_IO.Put (Item => E, Base => 16); (There are variants of Put that send the output to a File_Type or to a string). If you want to avoid the 16## part, you can easily convert the stream_elements to a string representation yourself like so: function To_Hex (E : in Ada.Streams.Stream_Element) return String is -- Warning: not compiled and not tested... X : constant array (0 .. 15) of Character := ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); Result : String (1 .. Ada.Streams.Stream_Element'Size / 4); -- 1 hex digits = 4 bits Working_Copy : Ada.Streams.Stream_Element := E; use type Ada.Streams.Stream_Element; First_Character : Natural := 0; Base : constant := 16; begin for K in reverse Result'Length loop Result (K) := X (Working_Copy mod Base); Working_Copy := Working_Copy / Base; if Working_Copy = 0 then First_Character := K; exit; end if; end loop; return Result (First_Character .. Result'Last); end To_Hex; Hope this helps. -- Ludovic Brenta.
From: tonyg on 19 Apr 2010 12:27 On Apr 19, 5:24 pm, Ludovic Brenta <ludo...(a)ludovic-brenta.org> wrote: > tonyg wrote on comp.lang.ada: > > > On Apr 19, 4:44 pm, tonyg <tonytheg...(a)googlemail.com> wrote: > > > > I have some data coming in from a serial port which I want to convert > > > to hexadecimal and display on the screen. I was wondering if anyone > > > knows of a simple way to do this? > > > To make myself more clear I have already dealt with the serial comms > > bit, I am looking to display the stream I have already captured > > You could use the predefined library to get a result using the Ada > "syntax for based literal" (ARM A.10.8(14)), e.g. 16#CE#. > > package Stream_Element_IO is > new Ada.Text_IO.Modular_IO (Num => Ada.Streams.Stream_Element); > > E : Ada.Streams.Stream_Element := ... > begin > Stream_Element_IO.Put (Item => E, Base => 16); > > (There are variants of Put that send the output to a File_Type or to a > string). > > If you want to avoid the 16## part, you can easily convert the > stream_elements to a string representation yourself like so: > > function To_Hex (E : in Ada.Streams.Stream_Element) return String is > -- Warning: not compiled and not tested... > X : constant array (0 .. 15) of Character := > ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', > 'D', 'E', 'F'); > Result : String (1 .. Ada.Streams.Stream_Element'Size / 4); -- 1 > hex digits = 4 bits > Working_Copy : Ada.Streams.Stream_Element := E; > use type Ada.Streams.Stream_Element; > First_Character : Natural := 0; > Base : constant := 16; > begin > for K in reverse Result'Length loop > Result (K) := X (Working_Copy mod Base); > Working_Copy := Working_Copy / Base; > if Working_Copy = 0 then > First_Character := K; > exit; > end if; > end loop; > return Result (First_Character .. Result'Last); > end To_Hex; > > Hope this helps. > > -- > Ludovic Brenta. Thanks Ludovic I'll try that.
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: Hexadecimal and stream element arrays Next: Help - removal from asiswg-members.html |