File tree Expand file tree Collapse file tree
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1769,20 +1769,26 @@ Object doGeneric(@SuppressWarnings("unused") Object self) {
17691769 }
17701770 }
17711771
1772- @ Builtin (name = "to_bytes" , minNumOfArguments = 1 , maxNumOfArguments = 2 )
1772+ @ Builtin (name = "to_bytes" , fixedNumOfArguments = 3 , takesVariableArguments = true )
17731773 @ GenerateNodeFactory
17741774 abstract static class ToBytesNode extends PythonBuiltinNode {
17751775 @ Specialization
1776- PBytes doInt (int self , int length ) {
1776+ PBytes doInt (int self , int length , String byteorder ) {
17771777 byte [] bytes = new byte [length ];
1778- for (int i = 0 ; i < length ; i ++) {
1779- bytes [i ] = (byte ) ((self >> i ) & 0xFF );
1778+ if (byteorder .equals ("big" )) {
1779+ for (int i = 0 ; i < length ; i ++) {
1780+ bytes [i ] = (byte ) ((self >> i ) & 0xFF );
1781+ }
1782+ } else {
1783+ for (int i = 0 ; i < length ; i ++) {
1784+ bytes [i ] = (byte ) ((self << i ) & 0xFF );
1785+ }
17801786 }
17811787 return factory ().createBytes (bytes );
17821788 }
17831789
17841790 @ Specialization
1785- PBytes doLong (long self , int length ) {
1791+ PBytes doLong (long self , int length , String byteorder ) {
17861792 byte [] bytes = new byte [length ];
17871793 for (int i = 0 ; i < length ; i ++) {
17881794 bytes [i ] = (byte ) ((self >> i ) & 0xFF );
You can’t perform that action at this time.
0 commit comments