-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringToHex.html
More file actions
50 lines (49 loc) · 1.48 KB
/
Copy pathStringToHex.html
File metadata and controls
50 lines (49 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>StringToHex</title>
<script>
function StringToHex( string )
{
var decl = "uint[]( ";
for ( i=0; i < string.length; i++ )
{
decl += "0x" + string.charCodeAt(i).toString(16)+"U";
if ( i < string.length-1 )
decl += ", ";
}
decl += " ) // length "+string.length.toString()+" = 0x"+string.length.toString(16);
document.forms['myForm']['hex'].value = decl;
var decl = "uint[]( ";
for ( i=0; i < string.length; i+=4 )
{
decl += "0x"
+ (
(string.charCodeAt(i+3)||0)*0x01000000
+ (string.charCodeAt(i+2)||0)*0x00010000
+ (string.charCodeAt(i+1)||0)*0x00000100
+ string.charCodeAt(i+0)
).toString(16)
+ "U";
if ( i < string.length-4 )
decl += ", ";
}
decl += " ) // length "+string.length.toString()+" = 0x"+string.length.toString(16);
document.forms['myForm']['hex32'].value = decl;
}
</script>
</head>
<body>
<!-- form passing textbox contents to StringToHex -->
<form name="myForm">
Input:<br>
<textarea name="textbox" rows="5" cols="30"></textarea><br>
<button type="button" onclick="return StringToHex(document.forms['myForm']['textbox'].value)">Submit</button><br>
Bytes:<br>
<textarea name="hex" rows="5" cols="30"></textarea><br>
Packed in uint32:<br>
<textarea name="hex32" rows="5" cols="30"></textarea>
</form>
</body>
</html>