code beauty... fiction ?
[1/6] from: hallvard::ystad::helpinhand::com at: 10-Oct-2001 21:13
When I do java programming, I have the types BYTE and SHORT. I haven't found this in
rebol, so I convert integers this way:
short: load rejoin ["#{" pick to-hex some-integer 5
pick to-hex some-integer 6
pick to-hex some-integer 7
pick to-hex some-integer 8
"}"]
byte: load rejoin ["#{" pick to-hex some-integer 7
pick to-hex some-integer 8
"}"]
I don't find this a very sexy way to do it. Has anyone got any suggestions to do it in
a more intuitive way?
~H
[2/6] from: al:bri:xtra at: 11-Oct-2001 8:32
Could you use tuple! datatype?
>> colour: 12.34.56
== 12.34.56
Andrew Martin
ICQ: 26227169 http://valley.150m.com/
[3/6] from: hallvard:ystad:helpinhand at: 10-Oct-2001 22:07
Well, then, If I have the integer value 71 (hex 47) and whish to save it to a file as
an eight-bit byte, how should I proceed with tuple! ?
~H
Du skrev (21.32 10.10.2001):
[4/6] from: mh983:ya:hoo at: 10-Oct-2001 15:44
how about :
short: at to-hex some-integer 5
byte: at to-hex some-integer 7
mike
[5/6] from: ryanc:iesco-dms at: 10-Oct-2001 14:55
I would not call these beauties, but they are smaller, so less ugliness to look at...
to-short: func [v][to-binary join to-char v / 256 to-char v // 256]
to-byte: func [v][to-binary to-char v // 256]
--Ryan
Hallvard Ystad wrote:
> When I do java programming, I have the types BYTE and SHORT. I haven't found this in
rebol, so I convert integers this way:
> short: load rejoin ["#{" pick to-hex some-integer 5
<<quoted lines omitted: 12>>
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Ryan Cole
Programmer Analyst
www.iesco-dms.com
707-468-5400
[6/6] from: g:santilli:tiscalinet:it at: 11-Oct-2001 11:18
Hallvard Ystad wrote:
> I don't find this a very sexy way to do it. Has anyone got any suggestions to do it
in a more intuitive way?
>> byte: make struct! [value [char]] [#"^(00)"]
>> byte/value: #"A"
== #"A"
>> third byte
== #{41}
>> short: make struct! [value [short]] [0]
>> short/value: 15342
== 15342
>> third short
== #{EE3B}
WARNING: machine dependend. As you can see, endianess counts.
This can be used to convert the other way around:
>> change third short #{FF0A}
== #{}
>> short/value
== 2815
This works on /View even without /Pro key.
Regards,
Gabriele.
--
Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted