java - Converting integers into bytes -


how following numbers, on byte conversion give results on right hand side ? guess when convert integer byte array, should convert each of digit of number correponding 4 byte array. here's cannot understand..

727 = 000002d7

1944 = 00000798

42 = 0000002a

edit: reading blog found these following lines:-

if working integer column names, example, each column name 4 bytes long. lets work column names 727, 1944 , 42.

the bytes associated these 3 numbers:

727 = 000002d7

1944 = 00000798

42 = 0000002a

link blog: http://www.divconq.com/2010/why-does-cassandra-have-data-types/

solution

the following give exact output in example:

public class main {     public static void main(final string[] args)     {         system.out.format("%08x\n", 727);         system.out.format("%08x\n", 1944);         system.out.format("%08x\n", 42);     } } 

and here expected output:

000002d7 00000798 0000002a 

explanation

how formatter works, format right left string says, x = format hexadecimal, 08 = pad left 8 characters 0 , % marks beginning of pattern.

you can use string.format("%08x", 727); accomplish same thing.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -