Decode Bit-coded

Post your Gambas programming questions here.
Post Reply
User avatar
tincho
Posts: 57
Joined: Wednesday 10th July 2019 1:12pm

Decode Bit-coded

Post by tincho »

Hello everyone.
I have a collection of numbers that according to the manual of the file I am trying to decode are bit-coded they should be 1, 2, 4, 16, 32, 64 but I get from the file:
1008, 992, 1017.
How do I decode the numbers in the second group to make them look like something in the first?
See index 70 for the list.
Attachments
lQwlw.png
lQwlw.png (37.6 KiB) Viewed 2913 times
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Decode Bit-coded

Post by vuott »

Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Decode Bit-coded

Post by cogier »

Is this what you are looking for?
TextBoxIn As TextBox
GridViewDisplay As GridView

Public Sub TextBoxIn_Change()

  Dim iLoop As Integer
  Dim sBin As String

  GridViewDisplay.Clear

  If Len(Trim(TextBoxIn.Text)) > 3 Then TextBoxIn.Text = Left(TextBoxIn.Text, -1)

  Try sBin = Bin(TextBoxIn.Text, 7)
  If Error Then
    If Trim(TextBoxIn.Text) = "" Then Return

    TextBoxIn.Text = Left(TextBoxIn.Text, -1)
  Endif

  If Val(TextBoxIn.Text) > 127 Then
    TextBoxIn.Clear
    Return
  End If

  For iLoop = 0 To 6
    GridViewDisplay[0, iLoop].Text = sBin[iLoop]
  Next

End

Public Sub Form_Open()

  Dim iLoop As Integer
  Dim sHeader As String[] = ["AutoCad\n64", "Resolved\n32", "Table entry\n16", "8", "Locked\n4", "Frozen\n2", "Frozen\n1"]

  With Me
    .H = 150
    .W = 500
    .Padding = 5
    .Arrangement = Arrange.Vertical
  End With

  With TextBoxIn = New TextBox(Me) As "TextBoxIn"
    .H = 28
    .PlaceHolder = "Enter an integer upto 127"
  End With

  With GridViewDisplay = New GridView(Me) As "GridViewDisplay"
    .Columns.Count = 7
    .Rows.Count = 1
    .Expand = True
    .Header = GridView.Horizontal
  End With

  For iLoop = 0 To 6
    GridViewDisplay.Columns[iLoop].Title = sHeader[iLoop]
    GridViewDisplay.Columns[iLoop].Alignment = Align.Center
  Next

End
User avatar
tincho
Posts: 57
Joined: Wednesday 10th July 2019 1:12pm

Re: Decode Bit-coded

Post by tincho »

Yes !!! exactly.
Before see your code i made this with the help of tercoide.
Public Function DWGFlag(iFlag As Integer, iPos As Integer) As Byte
  Dim t As String
  Dim b As Byte
  t = Bin(iFlag, 8)
  b = CByte(Mid(t, 9 - iPos, 1))
  Return b
End
Regards.
Martin.
Post Reply