PageRenderTime 24ms CodeModel.GetById 17ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/red-system/utils/int-to-bin.r

http://github.com/dockimbel/Red
R | 24 lines | 19 code | 5 blank | 0 comment | 0 complexity | 4b09fe22e2a2e9dafdfba0f7f6a5475d MD5 | raw file
 1REBOL [
 2	Title:   "Red/System integer! to binary! conversion library"
 3	Author:  "Nenad Rakocevic"
 4	File: 	 %int-to-bin.r
 5	Rights:  "Copyright (C) 2011 Nenad Rakocevic. All rights reserved."
 6	License: "BSD-3 - https://github.com/dockimbel/Red/blob/master/BSD-3-License.txt"
 7]
 8
 9
10int-to-bin: context [
11	little-endian?: yes
12	
13	set 'to-bin8 func [v [integer! char!]][
14		to binary! to char! 256 + v and 255
15	]
16
17	set 'to-bin16 func [v [integer! char!]][			;TBD: add big-endian support
18		reverse skip debase/base to-hex to integer! v 16 2
19	]
20
21	set 'to-bin32 func [v [integer! char!]][			;TBD: add big-endian support
22		reverse debase/base to-hex to integer! v 16
23	]
24]