Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python - what is max byte equivalent to java Byte.MAX_VALUE

Tags:

java

python

hbase

Does python have an equivalence to java's Byte.MAX_VALUE representing the max byte? I had a look at python sys module, I only managed to find sys.maxint. Does it have anything like sys.maxbyte?

UPDATE:

In my case, I am doing a Hbase Rowkey scan, My rowkey looks like rk1_rk2. In order to scan all results for rk1 without knowing exact rk2, My java code looks like:

byte[] startRowBytes = "rk1".getBytes(); 
byte[] endRowBytes = ("rk1" + (char) Byte.MAX_VALUE).getBytes(); 

HbaseScanQuery query = new   HbaseScanQuery(tableName, colFamily);
query.setStartRow(startRowBytes).setStopRow(endRowBytes);

I am just trying to work out the python equivalence of Byte.MAX_VALUE part.

like image 760
Shengjie Avatar asked Dec 05 '25 06:12

Shengjie


1 Answers

I think you will have to define the value yourself. A byte has 2^8 = 256 unique states and so the largest integer it can represent is 255. java's byte type, however, is a signed byte, so half the states are reserved for positives(and 0) and the other half is used for negatives. therefore the the equivalent of java's Byte.MAX_VALUE is 127, and the equivalent of java's Byte.MIN_VALUE is -128

Since python bytes are unsigned, the equivalent of java's Byte.MIN_VALUE would be 128 which is the representation of -128 in 2's compliment notation(the defacto standard for representing signed integers) thanks to Ignacio Vazquez-Abrams for pointing that out.

I haven't dealt with python in a while, but i believe what you want is ("rk1"+chr(127))


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!