1
%% Copyright (c) 1998 by Erik Johansson. All Rights Reserved
2
%% Time-stamp: <01/01/17 16:31:31 happi>
3
%% ====================================================================
4
%% Filename : hipe_converters.erl
5
%% Module : hipe_converters
8
%% History : * 1998-04-16 Erik Johansson (happi@csd.uu.se): Created.
11
%% $Date: 2001/07/16 20:45:04 $
13
%% ====================================================================
14
%% Exported functions (short description):
15
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17
-module(hipe_converters).
18
-export([bytelist_to_16bitlist/1,word_to_lo_16/1,word_to_hi_16/1,
19
tuple_to_word/1,word_to_tuple/1,int_to_hex/1,
22
bytelist_to_16bitlist([Byte1,Byte2,Byte3,Byte4|Rest]) ->
23
[(Byte1 bsl 8) bor Byte2,
24
(Byte3 bsl 8) bor Byte4 | bytelist_to_16bitlist(Rest)];
25
bytelist_to_16bitlist([Byte1,Byte2,Byte3]) ->
26
[(Byte1 bsl 8) bor Byte2,
28
bytelist_to_16bitlist([Byte1,Byte2]) ->
29
[(Byte1 bsl 8) bor Byte2,0];
30
bytelist_to_16bitlist([Byte1]) ->
32
bytelist_to_16bitlist([]) -> [].
34
word_to_lo_16(X) -> X band 16#ffff.
35
word_to_hi_16(X) -> (X bsr 16) band 16#ffff.
37
tuple_to_word({Hi,Lo}) -> (Hi bsl 16) bor Lo.
38
word_to_tuple(Word) -> {word_to_hi_16(Word),word_to_lo_16(Word)}.
40
int_to_hex(N) -> int_to_hex(N, $a-10).
41
int_to_Hex(N) -> int_to_hex(N, $A-10).
43
int_to_hex(N, LetterBase) ->
44
if N < 0 -> [$- | int_to_hex(-N, [], LetterBase)];
45
true -> int_to_hex(N, [], LetterBase)
48
int_to_hex(N, Tail, LetterBase) ->
52
if Digit < 10 -> Digit+$0;
53
true -> Digit+LetterBase
55
NewTail = [Char | Tail],
56
if NewN =:= 0 -> NewTail;
57
true -> int_to_hex(NewN, NewTail, LetterBase)