Dec 7, 2010 Replies: 78 It's occasionally useful to be able to poke around in things as arrays of bytes so this library lets you do it. It can transform arrays of primitive types to and from arrays of bytes with the "endian-ness" of the conversion specified. If you need endian-ness you will either know about it or rather quickly find out. Byte arrays can be transformed to and from a hexadecimal string representation. Strings can be transformed to and from arrays of Bytes using specified encodings and to and from arrays of Chars. An array copy method is thrown in for good measure. EDIT :- Version 1.1 posted. See post #4 for details. Download link: www.b4x.com/android/files/ByteConverter1.1.zip Last edited by a moderator: Dec 15, 2015 Click to expand...
It's occasionally useful to be able to poke around in things as arrays of bytes so this library lets you do it. It can transform arrays of primitive types to and from arrays of bytes with the "endian-ness" of the conversion specified. If you need endian-ness you will either know about it or rather quickly find out. Byte arrays can be transformed to and from a hexadecimal string representation. Strings can be transformed to and from arrays of Bytes using specified encodings and to and from arrays of Chars. An array copy method is thrown in for good measure. EDIT :- Version 1.1 posted. See post #4 for details. Download link: www.b4x.com/android/files/ByteConverter1.1.zip
K kimble01 Member Licensed User Longtime User Jan 30, 2014 #41 raphaelcno said: A byte is shown as a value between -128 and +127, so FF (255) is shown as -1. If you want to convert a byte to an integer value between 0 and 255, you can use this : Dim Int_Byte As Int Int_Byte = Bit.AND(0xff, Byte) Click to expand... Yes, that is exactly what I did!
raphaelcno said: A byte is shown as a value between -128 and +127, so FF (255) is shown as -1. If you want to convert a byte to an integer value between 0 and 255, you can use this : Dim Int_Byte As Int Int_Byte = Bit.AND(0xff, Byte) Click to expand... Yes, that is exactly what I did!
G gfpos New Member Licensed User Longtime User May 5, 2014 #42 hi agraham, i just downloaded you lib und tried to compile the example: ByteConverterDemo.b4a. unfortunately it does not compile. see the attached image. do you know, what is wrong? does it depend on my java-version? many thanks in advance Attachments compile-error.PNG 31.3 KB · Views: 836
hi agraham, i just downloaded you lib und tried to compile the example: ByteConverterDemo.b4a. unfortunately it does not compile. see the attached image. do you know, what is wrong? does it depend on my java-version? many thanks in advance
Erel B4X founder Staff member Licensed User Longtime User May 6, 2014 #43 Are you sure that you copied the jar file together with the XML file?
G gfpos New Member Licensed User Longtime User May 6, 2014 #44 Erel said: Are you sure that you copied the jar file together with the XML file? Click to expand... i copied into the wrong folder. after creating "additional library path" and copying both files in it everthing is fine. thank you
Erel said: Are you sure that you copied the jar file together with the XML file? Click to expand... i copied into the wrong folder. after creating "additional library path" and copying both files in it everthing is fine. thank you
C coolice New Member Licensed User Longtime User Aug 15, 2014 #45 Hello All. I'm new to the forum and new to trying to get my head around Android code. I stumbled across basic4android by chance and after a short while took the plunge and brought it. I must say I am impressed and am starting to learn my way around little by little around work. Basically I am looking to build and app that interrogates a Bluetooth module (HC-05) and sends it a hex command to generate a response, then displays the returned hex code interpreted as ASCII in various text boxes. Using the Bluetooth chat application as a starting point and with the tutorials here, I have managed to get the chat app to send out the hex code and receive the response, which when translated is giving me the information I'm requesting. However I am struggling to now find the lines of code I'd need to change this ASCII hex code to readable text. For example if I send 1C0A I get sent back 33 on one line and 322E34B043 on the 2nd, which is telling me the temperature reading. The last sub of the chat app; "Sub LogMessage(From AsString, Msg AsString) txtLog.Text = txtLog.Text & From & ": " & Msg & CRLF txtLog.SelectionStart = txtLog.Text.Length End Sub" So I'm guessing this is were I need to put another line of code or two, to take the received information and convert to display correctly. Various searches have not shown me anything obvious to try, other than what I already have and due to my newbie nature to Android coding it's taking me longer to work things out. I'm hoping that by working out what I need to do to the chat app, I can apply that knowledge to build the app I am looking for. Any help would be greatly appreciated on my exciting adventure of trying to learn the basics of what I'm trying to achieve. Ian P.S. Sorry, may have posted in the wrong thread. Have made a post in the Questions pages. Last edited: Aug 15, 2014
Hello All. I'm new to the forum and new to trying to get my head around Android code. I stumbled across basic4android by chance and after a short while took the plunge and brought it. I must say I am impressed and am starting to learn my way around little by little around work. Basically I am looking to build and app that interrogates a Bluetooth module (HC-05) and sends it a hex command to generate a response, then displays the returned hex code interpreted as ASCII in various text boxes. Using the Bluetooth chat application as a starting point and with the tutorials here, I have managed to get the chat app to send out the hex code and receive the response, which when translated is giving me the information I'm requesting. However I am struggling to now find the lines of code I'd need to change this ASCII hex code to readable text. For example if I send 1C0A I get sent back 33 on one line and 322E34B043 on the 2nd, which is telling me the temperature reading. The last sub of the chat app; "Sub LogMessage(From AsString, Msg AsString) txtLog.Text = txtLog.Text & From & ": " & Msg & CRLF txtLog.SelectionStart = txtLog.Text.Length End Sub" So I'm guessing this is were I need to put another line of code or two, to take the received information and convert to display correctly. Various searches have not shown me anything obvious to try, other than what I already have and due to my newbie nature to Android coding it's taking me longer to work things out. I'm hoping that by working out what I need to do to the chat app, I can apply that knowledge to build the app I am looking for. Any help would be greatly appreciated on my exciting adventure of trying to learn the basics of what I'm trying to achieve. Ian P.S. Sorry, may have posted in the wrong thread. Have made a post in the Questions pages.
T Turbo3 Active Member Licensed User Longtime User Dec 17, 2014 #46 When will a B4i version be available? ================ Never mind. I see it is built-in now. Last edited: Dec 17, 2014
Thuong Member Licensed User Longtime User Jun 2, 2015 #47 Dear I have array of hex [55 , 0A ,FA] and can i convert array to Int ?
Erel B4X founder Staff member Licensed User Longtime User Jun 2, 2015 #48 What do you mean with array of hex? Is this an array of strings?
stu14t Active Member Licensed User Longtime User Jun 2, 2015 #49 Thuong said: Dear I have array of hex [55 , 0A ,FA] and can i convert array to Int ? Click to expand... Try this thread it may be what you need: https://www.b4x.com/android/forum/threads/string-to-int-conversion.18387/#post-105464
Thuong said: Dear I have array of hex [55 , 0A ,FA] and can i convert array to Int ? Click to expand... Try this thread it may be what you need: https://www.b4x.com/android/forum/threads/string-to-int-conversion.18387/#post-105464
Thuong Member Licensed User Longtime User Jun 12, 2015 #50 Dear Sorry, I have a stream hex value [550AFA], I would like convert to integer is 5573370 Help me
stu14t Active Member Licensed User Longtime User Jun 12, 2015 #51 That code in the post I have shown will work but you will need to delineate the stream.
raphael75 Active Member Licensed User Longtime User Jun 12, 2015 #52 Thuong said: Sorry, I have a stream hex value [550AFA], I would like convert to integer is 5573370 Click to expand... How do you see the value '550AFA'? As a string?
Thuong said: Sorry, I have a stream hex value [550AFA], I would like convert to integer is 5573370 Click to expand... How do you see the value '550AFA'? As a string?
Thuong Member Licensed User Longtime User Jun 13, 2015 #53 Dear Raphaelcno I receive byte buffer from Bluetooth (value of analog), i can use Dim msg AsString msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8") then convert string to Int This is correct
Dear Raphaelcno I receive byte buffer from Bluetooth (value of analog), i can use Dim msg AsString msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8") then convert string to Int This is correct
stu14t Active Member Licensed User Longtime User Jun 13, 2015 #54 I think this is what you are trying to do Code: Copy Dim newval As Int Dim msg As String msg = BytesToString(buffer, 0, buffer.Length, "UTF8") newval = Bit.ParseInt(msg, 16) Log(newval)
I think this is what you are trying to do Code: Copy Dim newval As Int Dim msg As String msg = BytesToString(buffer, 0, buffer.Length, "UTF8") newval = Bit.ParseInt(msg, 16) Log(newval)
K kaudie Member Licensed User Longtime User Oct 12, 2015 #56 Why do I get an error when I try this? Dim Str_HexNumber As String Str_HexNumber = "DA2DDE56" Dim Int_Number As Int Int_Number = Bit.ParseInt(Str_HexNumber, 16) The error is: java.lang.NumberFormatException: Invalid int: "DA2DDE56" thanks
Why do I get an error when I try this? Dim Str_HexNumber As String Str_HexNumber = "DA2DDE56" Dim Int_Number As Int Int_Number = Bit.ParseInt(Str_HexNumber, 16) The error is: java.lang.NumberFormatException: Invalid int: "DA2DDE56" thanks
Erel B4X founder Staff member Licensed User Longtime User Oct 13, 2015 #57 Please start a new thread for this question. It is not related to this thread.
Kwame Twum Active Member Licensed User Longtime User Oct 22, 2015 #58 Hello guys, please why is no one paying attention to Post #20?
P power67 New Member Licensed User Longtime User Jan 13, 2016 #59 I installed the latest b4A and added the lib to my additional lib folder, however, I get the following error when compiling. anywheresoftware.b4a.agraham.byteconverter does not exist public static anywheresoftware.b4a.agraham.byteconverter.ByteConverter _conv = null; any advice would be great, I had this app working in previous version Thanks in advance for your assistance. Ross
I installed the latest b4A and added the lib to my additional lib folder, however, I get the following error when compiling. anywheresoftware.b4a.agraham.byteconverter does not exist public static anywheresoftware.b4a.agraham.byteconverter.ByteConverter _conv = null; any advice would be great, I had this app working in previous version Thanks in advance for your assistance. Ross
Erel B4X founder Staff member Licensed User Longtime User Jan 13, 2016 #60 Are you sure that the jar file was copied as well? Is ByteConverter library checked in the libraries list?
Are you sure that the jar file was copied as well? Is ByteConverter library checked in the libraries list?