Hex dump: Difference between revisions
Content deleted Content added
m →{{header|Phix}}: found an ugly way to make it js-compatible, size not final address |
m →{{header|Phix}}: much cleaner way |
||
Line 238: | Line 238: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<small>Aside: Phix does not really "do" utf-16, that is in source code terms, but declaring things as utf-8 and converting to utf-16 is not exactly hard. See talk page.</small> |
|||
<!--<syntaxhighlight lang="phix">(phixonline)--> |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #004080;"> |
<span style="color: #004080;">sequence</span> <span style="color: #000000;">utf16</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">#FEFF</span> <span style="color: #0000FF;">&</span> <span style="color: #008000;">"Rosetta Code is a programming chrestomathy site "</span> <span style="color: #0000FF;">&</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">#d83d</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#DE00</span><span style="color: #0000FF;">,</span><span style="color: #008000;">'.'</span><span style="color: #0000FF;">}</span> |
||
<span style="color: #004080;"> |
<span style="color: #008080;">function</span> <span style="color: #000000;">to2</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #0000FF;">{</span><span style="color: #7060A8;">and_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#FF</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">/</span><span style="color: #000000;">#100</span><span style="color: #0000FF;">)}</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
||
<span style="color: #008080;">constant</span> <span style="color: #004080;">string</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;"> |
<span style="color: #008080;">constant</span> <span style="color: #004080;">string</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">flatten</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #000000;">utf16</span><span style="color: #0000FF;">,</span><span style="color: #000000;">to2</span><span style="color: #0000FF;">),</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #000080;font-style:italic;">--or: |
<span style="color: #000080;font-style:italic;">--or: (javascript incompatible) |
||
--constant string s = get_text(filename) -- (if you have a suitable premade one to hand) |
--constant string s = get_text(filename) -- (if you have a suitable premade one to hand)</span> |
||
--or: (javascript compatible) |
|||
--constant string s = "\xFF\xFER\0o\0s\0e\0t\0t\0a\0 \0C\0o\0d\0e\0 \0i\0s\0 \0a\0 "& |
|||
-- "\0p\0r\0o\0g\0r\0a\0m\0m\0i\0n\0g\0 \0c\0h\0r\0e\0s\0t\0o\0m\0a\0t\0h\0y\0 "& |
|||
-- "\0s\0i\0t\0e\0 \0=\xD8\0\xDE.\0"</span> |
|||
<span style="color: #008080;">procedure</span> <span style="color: #000000;">hexdump</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">start</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">finish</span><span style="color: #0000FF;">=-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">bool</span> <span style="color: #000000;">bHex</span><span style="color: #0000FF;">=</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">bFinalSize</span><span style="color: #0000FF;">=</span><span style="color: #004600;">true</span><span style="color: #0000FF;">)</span> |
<span style="color: #008080;">procedure</span> <span style="color: #000000;">hexdump</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">start</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">finish</span><span style="color: #0000FF;">=-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">bool</span> <span style="color: #000000;">bHex</span><span style="color: #0000FF;">=</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">bFinalSize</span><span style="color: #0000FF;">=</span><span style="color: #004600;">true</span><span style="color: #0000FF;">)</span> |