• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Converting byte array to biginteger?

 
Marshal
Posts: 69813
277
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tushar Goel wrote: . . .. First you move 0x20(32) position to the left and makes it signed then you right shift it 32 position and makes it unsigned. . . .

I tried a bitwise AND with -1 but even casting it to an int didn't help. What you are doing with the << 0x20 is moving the entire number 0x20 bits to the left, so the right half consists entirely of 0s. All 32 lower order bits are now on the left. Then you move the whole lot back so the right 32 lower order bits are replaced where they started but the left half is filled with 0s. I should have written line 9 like this:-
System.out.printf("The bottom 32 bits of i unsigned are %d=0x%<x%n",
… then you can see the hex output for 3158851493 which will of course be bc483fa5.
 
Campbell Ritchie
Marshal
Posts: 69813
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tushar Goel wrote:

. . . If your technical people have been using this in the generation of format preserving encryption . . .


Let me speak to them. May be they understand.

No, just shoot them
 
Campbell Ritchie
Marshal
Posts: 69813
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Had you simply cast that output (3158851493) to an int, it would have been negative, so you would not have seen the decimal output.
 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell and Richard. I have gone through some tutorials on bit shift operation. I am much clear now.

And understand now, what Campbell did. Thanks again..
 
Campbell Ritchie
Marshal
Posts: 69813
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Would anybody like some fudge? I made it an hour ago. And it goes well with a tiny ad ...
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic