I wish to convert an integer number to hexadecimal. For example 255 would become a single byte FF.
Any hints?
Regards,
Loffy
-
- VIP Member
- Posts: 58
- Joined: 11 Jul 2002 23:01
Re: Convert integer to hexadecimal
Hello Lofty
Here are two possibilities.
Use the helpfile for information about class binary.
You get this output:
$[FF]
$[FF,00,00,00,FE,00,00,00]
Here are two possibilities.
Use the helpfile for information about class binary.
Code: Select all
predicates
testing : ().
clauses
testing() :-
% For manipulating bytes (in hexadecimal form) you need class binary
Binary1 = binary::createAtomic(1),
binary::setIndexed_unsigned8(Binary1, 0, 255),
stdio::write(Binary1, "\n"),
%
% A second possibility
Binary2 = binary::createAtomicFromIntegerList([255, 254]),
stdio::write(Binary2).
$[FF]
$[FF,00,00,00,FE,00,00,00]
-
- VIP Member
- Posts: 459
- Joined: 5 Nov 2000 0:01
Re: Convert integer to hexadecimal
string::format
Code: Select all
% Try this:
R = 12,
S = string::format("%1x", R),
stdio::write("\n", R, "\t", S), % S = "C"
-
- Active Member
- Posts: 47
- Joined: 15 Aug 2019 11:32
Re: Convert integer to hexadecimal
Thank you both.
I can see reasons to use both suggestions.
Loffy
I can see reasons to use both suggestions.
Loffy
-
- Active Member
- Posts: 47
- Joined: 15 Aug 2019 11:32
Re: Convert integer to hexadecimal
Tested and working.
Just as a thought, and possibly not an elegant solution, would creating a custom symbol table domain have worked?
Regards,
Loffy
Just as a thought, and possibly not an elegant solution, would creating a custom symbol table domain have worked?
Regards,
Loffy