########################################################################### ## #W omputbin.gi OpenMath Package Max Nicosia ## ## #Y Copyright (C) 1999, 2000, 2001, 2006 #Y School Math and Comp. Sci., University of St. Andrews, Scotland #Y Copyright (C) 2004, 2005, 2006 Marco Costantini ## ## Low-level methods for output in the OpenMath binary format ##
########################################################################### ## #M BigIntToListofInts( <integer> ) ## ## Returns a list of 4 integers as to represent the number over 4 bytes ##
BindGlobal ( "BigIntToListofInts", function(int)
local hexValue, hexValueLength, finalHexString, lengthDiff, listofInts;
listofInts:=[];
finalHexString := "";
hexValue := HexStringInt(int);
hexValueLength := Length(hexValue); if (hexValueLength < 8) then
lengthDiff := 8 - hexValueLength; while lengthDiff > 0do
Append(finalHexString,"0");
lengthDiff := lengthDiff - 1;
od; fi;
Append(finalHexString, hexValue);
Add(listofInts, IntHexString(finalHexString{[1..2]}));
Add(listofInts, IntHexString(finalHexString{[3..4]}));
Add(listofInts, IntHexString(finalHexString{[5..6]}));
Add(listofInts, IntHexString(finalHexString{[7..8]}));
return listofInts; end);
########################################################################### # #M IsIntFloat( <object> ) # # Checks whethere it is a real float
BindGlobal( "IsIntFloat", function(x)
return Float(0) = x-Float(Int(x)); end);
########################################################################### ## #M CreateListWithFalses( <integer> ) ## ## Returns a list with the number of falses specified, ## if 0 then returns an empty list. ##
BindGlobal( "CreateListWithFalses", function(numFalses)
local listFalses, i;
listFalses := []; for i in [1..numFalses] do
listFalses[i]:=false;
od;
return listFalses; end);
########################################################################### ## #M WriteIntasBytes( <stream>, <list> ) ## ## Writes an integer as four bytes given a list representing the integer, ## in binary and the stream ##
BindGlobal( "WriteIntasBytes", function( stream, listofInts )
WriteByte(stream, listofInts[1]);
WriteByte(stream, listofInts[2]);
WriteByte(stream, listofInts[3]);
WriteByte(stream, listofInts[4]); end);
########################################################################### ## #M FindFirst1BinaryString( <string> ) ## ## Obtains position of first 1 in the binary string ##
BindGlobal( "FindFirst1BinaryString", function( binStri )
local i, binStriLen;
binStriLen := Length(binStri);
i := 1; while binStri[i] <> '1' and i <= binStriLen do
i := i +1;
od;
return i; end);
########################################################################### ## #M WriteDecasHex( <float> ) ## ## Returns the decimal number in a hexadecimal representation ##
BindGlobal( "WriteDecasHex", function( decPart )
local intPart, resultHex, number, i, zeroF;
i := 0;
resultHex := "";
zeroF := Float("0.0"); while decPart <> zeroF do if i > 10then
break; fi;
number := decPart * 16;
intPart := Int(number);
decPart := number - intPart;
Append(resultHex, HexStringInt(intPart));
i := i +1;
od;
return resultHex;
end);
########################################################################### ## #M WriteHexAsBin( <hexNum>, <bool> ) ## ## Returns the given hexadecimal number as a binary string. ## Leading zeroes are included if the flag is set to TRUE. ##
BindGlobal( "WriteHexAsBin", function( hexNum, withLeadingZeroes )
local hexNumLen, binStri, num, charStri, counter,
binArrayWithZeroes, binArrayNoLeadingZeroes;
hexNumLen := Length(hexNum);
binStri := "";
counter:= 1;
binArrayWithZeroes :=
["0000", "0001" ,"0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"];
binArrayNoLeadingZeroes :=
["", "1" ,"10", "11", "100", "101", "110", "111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"];
charStri := hexNum{[counter]};
num := IntHexString(charStri); if withLeadingZeroes then
Append(binStri, binArrayWithZeroes[num+1]); else
Append(binStri, binArrayNoLeadingZeroes[num+1]); fi;
counter := counter +1; while counter <= hexNumLen do
charStri := hexNum{[counter]};
num := IntHexString(charStri);
Append(binStri, binArrayWithZeroes[num+1]);
counter := counter +1;
od;
return binStri; end);
########################################################################### ### ##M ## removes all falses at the start of the list. #BindGlobal( "NormaliseBlist", #function( list ) #local i, listLen, finalList; #i:= 1; #listLen := Length(list); #while i <= listLen and list[i] = false do # i := i +1; #od; #if i >= listLen then # finalList := [list[listLen]]; #else # finalList := list{[i..listLen]}; #fi; #list := finalList; #return i; #end);
########################################################################### ## #M WriteHexStriAsBytes( <string>, <stream> ) ## ## Writes the hexadecimal string to the stream as bytes. ##
BindGlobal( "WriteHexStriAsBytes", function( hexStri, stream )
local hexStriLen, intValue, upper, lower;
upper := 2;
lower := 1;
intValue := 0;
hexStriLen := Length(hexStri); while upper <= hexStriLen do
intValue := IntHexString(hexStri{[lower..upper]});
WriteByte(stream, intValue);
upper := upper +2;
lower := lower +2;
od; end);
########################################################################### ## #M OMPut( <OMWriter>, <int> ) ## ## Printing for integers: specified in the standard ##
InstallMethod(OMPut, "for an integer to binary OpenMath", true,
[ IsOpenMathBinaryWriter, IsInt ],0, function( writer, int )
local intStri, intLength, intListLength;
intStri := String(AbsInt(int));
intLength := Length(intStri);
if int >= -128 and int <= 127then
WriteByte( writer![1], 1); if int < 0then
int := 256 + int; fi;
WriteByte(writer![1], int);
elif int >= -2^31 and int <= 2^31-1then
WriteByte( writer![1], 129); #1+128 if int < 0then
int := 2^32 + int; fi;
intListLength := BigIntToListofInts(int);
WriteIntasBytes(writer![1], intListLength);
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.273Bemerkung:
(vorverarbeitet am 2026-10-14)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.