~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to lib/hipe/misc/hipe_converters.erl

  • Committer: Bazaar Package Importer
  • Author(s): Erlang Packagers, Sergei Golovan
  • Date: 2006-12-03 17:07:44 UTC
  • mfrom: (2.1.11 feisty)
  • Revision ID: james.westby@ubuntu.com-20061203170744-rghjwupacqlzs6kv
Tags: 1:11.b.2-4
[ Sergei Golovan ]
Fixed erlang-base and erlang-base-hipe prerm scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
6
 
%%  Purpose  :  
7
 
%%  Notes    : 
8
 
%%  History  :  * 1998-04-16 Erik Johansson (happi@csd.uu.se): Created.
9
 
%% CVS:
10
 
%%    $Author: mikpe $
11
 
%%    $Date: 2001/07/16 20:45:04 $
12
 
%%    $Revision: 1.2 $
13
 
%% ====================================================================
14
 
%% Exported functions (short description):
15
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16
 
 
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,
20
 
         int_to_Hex/1]).
21
 
 
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,
27
 
   (Byte3 bsl 8)];
28
 
bytelist_to_16bitlist([Byte1,Byte2]) ->
29
 
  [(Byte1 bsl 8) bor Byte2,0];
30
 
bytelist_to_16bitlist([Byte1]) ->
31
 
  [(Byte1 bsl 8),0];
32
 
bytelist_to_16bitlist([]) -> [].
33
 
 
34
 
word_to_lo_16(X) -> X band     16#ffff.
35
 
word_to_hi_16(X) -> (X bsr 16) band 16#ffff.
36
 
 
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)}.
39
 
 
40
 
int_to_hex(N) -> int_to_hex(N, $a-10).
41
 
int_to_Hex(N) -> int_to_hex(N, $A-10).
42
 
 
43
 
int_to_hex(N, LetterBase) ->
44
 
    if N < 0 -> [$- | int_to_hex(-N, [], LetterBase)];
45
 
       true -> int_to_hex(N, [], LetterBase)
46
 
    end.
47
 
 
48
 
int_to_hex(N, Tail, LetterBase) ->
49
 
    NewN = N bsr 4,
50
 
    Digit = N band 15,
51
 
    Char =
52
 
        if Digit < 10 -> Digit+$0;
53
 
           true -> Digit+LetterBase
54
 
        end,
55
 
    NewTail = [Char | Tail],
56
 
    if NewN =:= 0 -> NewTail;
57
 
       true -> int_to_hex(NewN, NewTail, LetterBase)
58
 
    end.