Skip to contents

Convert 8, 16, or 32-bit signed or unsigned integer values into raw data, conform Amiga specifications.

Usage

amigaIntToRaw(x, bits = 8, signed = F)

Arguments

x

A vector of class numeric which needs to be converted into raw values.

bits

Number of bits that represents the integer value. Should be 8 or a positive multitude of 8.

signed

A logical value indicating whether the numeric values is signed (TRUE, default) or not (FALSE).

Value

Returns (a vector of) raw data, representing the integer value(s) conform Amiga specifications.

Details

The Commodore Amiga has specified the following data formats to represent integer data: BYTE (signed 8-bit integer), UBYTE (unsigned 8-bit integer), WORD (signed 16-bit integer), UWORD (unsigned 16-bit integer), LONG (signed 32-bit integer), ULONG, (unsigned 32-bit integer). This function converts such integers into raw data.

See also

Author

Pepijn de Vries

Examples

## some unsigned 8-bit integers:
ubyte <- sample.int(255, 100, TRUE)

## The same values as raw data:
amigaIntToRaw(ubyte)
#>   [1] ad 97 cc 3f e5 66 6f 2f 9f c4 e6 c9 c5 05 ff 18 4f 4d 82 be 37 ab 3e 2b 05
#>  [26] d5 2c bd 22 46 ff bf 04 f0 a2 a3 d9 d6 2b 87 20 b5 46 09 96 ff 0a a0 75 a2
#>  [51] 11 b4 b8 16 5f 81 46 a2 b3 ae 41 19 ef f2 a5 08 a1 e0 6c 53 5c 1c 30 4b da
#>  [76] 23 82 57 6a 83 26 c4 ea 41 e7 86 96 93 f9 02 40 28 c1 9c e1 c7 0c b6 29 2a

## some signed 8-bit integers:
byte <- sample.int(255, 100, TRUE) - 128

## The same values as raw data:
amigaIntToRaw(byte, signed = TRUE)
#>   [1] c2 e6 e7 6c 9a bc 76 8e 85 67 f3 4c 71 e5 91 8d 66 e1 21 cd 52 a0 45 b7 8b
#>  [26] 21 a4 87 17 58 a2 48 c9 b3 e9 3b 7d 26 ed 6d 99 b5 23 ad 52 17 74 2b 84 22
#>  [51] a9 d2 de 13 4c b3 00 11 4a 6c 8d 30 a7 55 64 41 83 87 31 46 5b 8c a7 0b aa
#>  [76] a8 76 f1 6c 74 8f 52 ac 36 d5 ba 9d ca 43 64 6d e6 0e c2 79 45 73 52 a5 6a

## some signed 16-bit integers:
word <- sample.int(2^16, 100, TRUE) - 2^15

## The same values as raw data:
amigaIntToRaw(word, 16, TRUE)
#>   [1] 72 84 88 38 5a b9 b5 d7 71 dd 47 f8 60 18 7b c9 42 59 43 49 a3 59 27 ef 28
#>  [26] 31 7a bf 5f 65 b7 f4 e3 bb 1d ef e8 28 04 87 84 5c df 0c 2d 90 41 8c bd 42
#>  [51] ea d2 23 40 75 a1 8c da b7 c9 70 2b 42 10 0b fc e3 6b 30 d4 72 41 77 f9 26
#>  [76] 7d 92 2b 43 74 0d 6f 87 f2 ad ba 62 be 1a fa 89 32 98 13 e7 de a0 62 b7 65
#> [101] b4 33 53 d8 c2 de 83 c8 ea 00 38 12 79 8f ab a0 87 eb aa a7 49 35 77 1a ac
#> [126] a5 4e 33 3b a1 84 19 2f a2 d3 cd 35 1f 6c f8 18 91 11 21 18 30 17 ea e5 d5
#> [151] 3d ea 9c 98 4c d4 8d 7e 1a ac 09 ed 76 94 a9 53 78 7f 62 96 88 f0 24 fc d0
#> [176] 8e 0a 54 03 fe 5b 46 80 07 71 fa 61 85 81 08 b8 20 3a 4b e1 ca 58 08 89 d6

## note that 16-bit integers require
## twice as many raw values:
length(amigaIntToRaw(word, 16, TRUE))
#> [1] 200
length(amigaIntToRaw(byte, 8, TRUE))
#> [1] 100