PC Review


Reply
Thread Tools Rate Thread

Big-Endian bit conversion

 
 
DIOS
Guest
Posts: n/a
 
      7th Jul 2010
I am struggling to write a converter from bits to a hex string. What I
am trying to do is to get the users inputs as far as what bits are
turned on and converting it to a hex. Problem here is that the target
system is Big-Endian so that format is the most significant bit and
byte is on the left. For example if the user selects bit-0 to ON then
the conversion is '80000000'x. Similarly if bit-4 is ON then the hex
is '08000000'x. In my documentation an example is bits 1,3,4,5,9,11,
and 17 turned on should give me a string of '5C504000'x. Im feeding
this hex string to a taget system so am not using it on the PC.

I have so far

Dim myBitArr As New BitArray(80, False)

'setup the bits that are turned ON
myBitArr(0) = True

'convert to decimal system
Dim result As Int32 = 0
For i As Int32 = 0 To myBitArr.Length - 1
If myBitArr(i) Then
result = CInt(result + System.Math.Pow(2, i))
End If
Next

Dim abyt() As Byte = BitConverter.GetBytes(result)
If BitConverter.IsLittleEndian Then
Array.Reverse(abyt)
End If

Console.WriteLine(BitConverter.ToString(abyt))

When i test this with bits 1,3,4,5,9,11, and 17 turned on I just cant
get hex equivalent of '5C504000'x
Any help is appreciated as my research into this type of conversion is
just hit a wall.

AGP
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Big-endian long <--> byte[8] conversion Marc Gravell Microsoft C# .NET 5 1st Aug 2006 01:33 PM
Byte Ordering : Little endian - Big Endian : Binary Files mohamed.alam78@gmail.com Microsoft C# .NET 5 22nd Jul 2006 08:26 PM
Re: TCP/IP endian conversion with ICustomMarshaler? Marquee Microsoft C# .NET 0 6th Aug 2004 07:47 PM
TCP/IP endian conversion with ICustomMarshaler? Marquee Microsoft C# .NET 1 6th Aug 2004 12:42 AM
Big endian / Little endian question David Lindgren Windows XP Hardware 4 20th Apr 2004 01:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:53 AM.