users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re[1] Re[1] hexstring help


From: Renaud Mariana
Subject: Re[1] Re[1] hexstring help
Date: Fri, 01 Feb 2002 16:18:31 GMT+1

... Yes, and reversely for

hexstring(String,
[160,0,0,0,48,0,2,255,255,255,255,137,0,1,0,1]).

use a stream for writing to String.

Thanks

Renaud

> -------Message d'origine-------
> De : Henk Vandecasteele <address@hidden>
> Date : 01/02/2002 09:24:30
>
>
> This is how I would try to solve it:
>
> - first open a stream, that reads from that the string of
hexcodes. Most
> prolog-systems provide this, I don't know about GNU-
Prolog. A way
> around is to write the string to file and then open it
for reading
> (as I did below).
> - next read two characters at the time and translate
them, and next
> unify them against the next element in the list.
>
>
> This avoids translating the whole list to character-codes
in advance.
> Saving space, and time when for example the first
elements in the list
> do not match.
>
> Here my tryout, I'm ashamed to say that I don't know
how "iso" the
> program is:
>
>
> hexstring(String, List):-
> tell(tmp),
> write(String),
> told,
> see(tmp),
> ( read_and_match(List) ->
> seen
> ;
> /* close the file on failure as well. */
> seen,
> fail
> ).
>
>
> read_and_match([]):-
> at_end_of_stream.
> read_and_match(List):-
> \+ at_end_of_stream,
> List = [Byte|List1],
> get_char(C1),
> get_char(C2),
> match(C1, C2, Byte),
> read_and_match(List1).
>
> get_char(C):-
> get0(Code),
> atom_codes(C, [Code]).
>
>
> match( C1, C2, Byte):-
> match(C1, N1),
> match(C2, N2),
> Byte is N1 * 16+ N2.
>
>
>
> match('0', 0).
> match('1', 1).
> match('2', 2).
> match('3', 3).
> match('4', 4).
> match('5', 5).
> match('6', 6).
> match('7', 7).
> match('8', 8).
> match('9', 9).
> match('A', 10).
> match('B', 11).
> match('C', 12).
> match('D', 13).
> match('E', 14).
> match('F', 15).
>
> /*
>
> using:
>
> ?- [hex].
> Yes
> ?- hexstring('A0000000300002FFFFFFFF8900010001', L).
> L = [160,0,0,0,48,0,2,255,255,255,255,137,0,1,0,1]
> Yes
> ?- hexstring('A0000000300002FFFFFFFF8900010001',
> [160,0,0,0,48,0,2,255,255,255,255,137,0,1,0,1]).
> Yes
> ?- hexstring('A0000000300002FFFFFFFF8900010001',
> [160,0,0,0,48,0,2,255,255,255,255,137,0,1,0,0]).
> No more !
>
> ?-
>
> */
>

_________________________________________________________
Le journal des abonnés Caramail - http://www.carazine.com


reply via email to

[Prev in Thread] Current Thread [Next in Thread]