473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to convert this function into java?

m.j
Hi,

How to convert this pascal(delphi) function into java?
The function is used in a algorithm.

The trouble is that java don't have any unsigned 32bit type.

What the trick, when you cannot do bit shifting probaly,
because only signed types are aval.?
B12Ar is a array of 12 bytes(0..11), and can be anything.
"P" can be "0" or "8".
"k" can be "10" or "31".
-----------
procedure Cyc32(var Buf: B12Ar;P: byte;k: integer);
var
i : integer;
x,y : Longword;

begin
x := Buf[P];
x := x shl 8;
x := x or Buf[P + 1];
x := x shl 8;
x := x or Buf[P + 2];
x := x shl 8;
x := x or Buf[P + 3];

for i := 1 to k do
begin
// Cyclical Rotate 32 bits word right k times
y := x and 1; // Extract Carry
y := y shl 31; // Move Carry to Msb
x := x shr 1; // Do Shift
x := x or y; // Add Carry
end;

Buf[P + 3] := x;
x := x shr 8;
Buf[P + 2] := x;
x := x shr 8;
Buf[P + 1] := x;
x := x shr 8;
Buf[P] := x;
end;
-----------
--
Best regrads
M.J
Jul 17 '05 #1
2 2590
In Java there are three shift operators:
<<
use this one

Make sure you read a good Java book. It pays.

"m.j" <sc********@hotmail.com> wrote in message
news:3f*********************@dtext02.news.tele.dk. .. Hi,

How to convert this pascal(delphi) function into java?
The function is used in a algorithm.

The trouble is that java don't have any unsigned 32bit type.

What the trick, when you cannot do bit shifting probaly,
because only signed types are aval.?
B12Ar is a array of 12 bytes(0..11), and can be anything.
"P" can be "0" or "8".
"k" can be "10" or "31".
-----------
procedure Cyc32(var Buf: B12Ar;P: byte;k: integer);
var
i : integer;
x,y : Longword;

begin
x := Buf[P];
x := x shl 8;
x := x or Buf[P + 1];
x := x shl 8;
x := x or Buf[P + 2];
x := x shl 8;
x := x or Buf[P + 3];

for i := 1 to k do
begin
// Cyclical Rotate 32 bits word right k times
y := x and 1; // Extract Carry
y := y shl 31; // Move Carry to Msb
x := x shr 1; // Do Shift
x := x or y; // Add Carry
end;

Buf[P + 3] := x;
x := x shr 8;
Buf[P + 2] := x;
x := x shr 8;
Buf[P + 1] := x;
x := x shr 8;
Buf[P] := x;
end;
-----------
--
Best regrads
M.J

Jul 17 '05 #2
m.j
Hi,
In Java there are three shift operators:
<<

use this one
Hmm don't seem like there is any diff between >> and >>> in my JVM.
(Still have to AND result, to set prior bits to 0)??

But thanks anyway,
i got it working now.
Added some AND 0xff and stuff like that also, and then it suddenly worked.
Make sure you read a good Java book. It pays.

I will do, do you know any good internet links?

Thanks!

--
Best regrads
M.J
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP...
2
by: Barney | last post by:
I have to convert a Java app to .NET, i found and used the conversion tool which converts java to C#, but it only converted about 10% of it, how hard would it be to re-write the java app and keep...
17
by: Terry Jolly | last post by:
New to C# ---- How do I convert a Date to int? In VB6: Dim lDate as long lDate = CLng(Date) In C#
4
by: faizal87 | last post by:
hallo...can i get some knowladge...about java script convert to V.B....how??like 'calculation downloadable',i've get a formula calculate but in java script....how i want convert this language to V.B...
7
by: shellon | last post by:
Hi all: I want to convert the float number to sortable integer, like the function float2rawInt() in java, but I don't know the internal expression of float, appreciate your help!
2
by: Galil | last post by:
I have a subroutine I need to convert from vb.net 2005 to visual C++ ( .net 2005) The function only allows specific characters to be typed into a textbox. the backspace and 0 -9. Private Sub...
6
by: Ty | last post by:
Here is another block that I can not get to convert. This is a class module. public bool IsAuthenticated(string domain, string username, string pwd) { string domainAndUsername = domain + @"\"...
3
by: Smokey Grindel | last post by:
I understand generics in VB.NET but how do you convert this C# code to VB.NET? /// <summary> /// Routing handler. /// </summary> /// <typeparam name="T">Type of <see...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.