# Converting string of bytes to integer

**URL:** <https://discourse.julialang.org/t/converting-string-of-bytes-to-integer/58962>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 10, 2021, 3:04am UTC](https://discourse.julialang.org/t/converting-string-of-bytes-to-integer/58962 "2021-04-10T03:04:12Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![SudhakarKuma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sudhakarkuma/32/23800_2.png) [@SudhakarKuma](https://discourse.julialang.org/u/SudhakarKuma)\
**Post date:** [April 10, 2021, 2:18pm UTC](https://discourse.julialang.org/t/converting-string-of-bytes-to-integer/58962/4 "2021-04-10T14:18:24Z")

</div>

I got this working by rewriting the function as given below:

```julia
function analogRead(file_des::SerialPorts.SerialPort , pin_no::Int64)
  str = "A"*string(Char(48+pin_no)) #"An" for analog value on pin n
  write(file_des,str)
  sleep(0.1) # Delay next step by 100 milliseconds
  n = bytesavailable(file_des) # Get number of bytes in input buffer
  s = read(file_des, n) # Read n bytes from SerialPort
  iolit = IOBuffer(s) 
  num = read(iolit, Int16)
  # println(sizeof(num))
  # println(num[1])
  # @printf("value = %d", Int(num))
  close(iolit)
  
  # typeof(s) 
  # k = parse(Int,s) # Convert String to integer
  return num # Return the integer
end

```

Thank you, @Benny, for your response.

---

_[View the full topic](https://discourse.julialang.org/t/converting-string-of-bytes-to-integer/58962)._
