Convert integer to hexadecimal
Posted: 26 Aug 2019 6:45
I wish to convert an integer number to hexadecimal. For example 255 would become a single byte FF.
Any hints?
Regards,
Loffy
Any hints?
Regards,
Loffy
Visual Prolog Discussion forums
https://discuss.visual-prolog.com/
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).
Code: Select all
% Try this:
R = 12,
S = string::format("%1x", R),
stdio::write("\n", R, "\t", S), % S = "C"