Click here to Skip to main content
16,018,664 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello
This function is written using Pascal software. Someone can guide what this function does?
Thanks .. 

procedure int2Hex(intnum:integer; var Bytes:Tsb8);
var  b,b1,b2,b3,b4,b5,b6,b7,b8:byte;
     n:integer;
begin
n:= intnum;
b:=n;

b8:=b AND $0f;
b7:=b AND $f0;  b7:=b7 shr 4;


n:=n shr 8;
b:=n;
b6:=b AND $0f;
b5:=b AND $f0;  b5:=b5 shr 4;


n:=n shr 8;
b:=n;
b4:=b AND $0f;
b3:=b AND $f0;  b3:=b3 shr 4;

n:=n shr 8;
b:=n;
b2:=b AND $0f;
b1:=b AND $f0;  b1:=b1 shr 4;

end;


What I have tried:

What I do know is that this function takes a number and stores it in an 8-byte array?
But I do not know how he does it?
I want to implement this function in C#.
thanks for your help 
Posted
Updated 17-Jan-22 2:08am

C#
public static  byte [] getNibbles(UInt32 ui32)
 {
 	const int Nibbles = 8;
 	byte [] b = new byte[Nibbles];
 	for ( int n=0; n<Nibbles; ++n)
 	{
 		b[n] = (byte) (ui32 & 0xF);
 		ui32 >>= 4;
 	}
 	return b;
 }
 
Share this answer
 
Comments
Member 9439045 17-Jan-22 23:26pm    
Thank you for help.
All it does is mask and shift values: Look up the AND and shr operators and it's pretty obvious: Pascal - Bit Operators[^]
 
Share this answer
 
Comments
Member 9439045 17-Jan-22 23:26pm    
Thank you for help.
OriginalGriff 18-Jan-22 1:35am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900