So Im trying to generate a Byte
Dim test as Byte = 0
Where I manipulate the Bits myself:
If ... Then test += 1
If ... Then test += 2
If ... Then test += 4
If ... Then test += 8
But with Option Strict On, the studio wants me to convert what im adding into Byte. This clearly is not the correct way, how can I do it correctly?
Related
I have a text file where the first few lines are text and the rest of the lines contain data in the form of real numbers. I just require the real numbers array to be stored in a new file. For this, I read the total lines of the file for which output is correct and then trying to read the real numbers from the particular line numbers. I am unable to understand as to how to read this data.
Below is a part of file. Also I have many files like these to read.
AptitudeQT paperI: 12233105
Latitude : 30.00 S
Longitude: 46.45 E
Attemptone Time: 2017-03-30-09-03
End Time: 2017-03-30-14-55
Height(agl): m
Pressure: hPa
Temperature: deg C
Humidity: %RH
Uvelocity: cm/s
Vvelocity: cm/s
WindSpeed: cm/s
WindDirection: deg
---------------------------------------
10 1008.383 27.655 62.200 -718.801 -45.665 720.250 266.500
20 1007.175 27.407 62.950 -792.284 -18.481 792.500 268.800
There are many examples how to skip/read lines like this
But to sum it up, option A is to skip header and read only data:
! Skip first 17 lines
do i = 1, 17
read (unit,*,IOSTAT=stat) ! Dummy read
if ( stat /= 0 ) stop "error"
end do
! Read data
do i = 1, 1000
read (unit,*,IOSTAT=stat) data(:,i)
if ( stat /= 0 ) stop "error"
end do
If you have many files like this, I suggest wrapping this in a subroutine/function.
Option B is to use unix tail utility to discard header (more info here):
tail -n +18 file.txt
I set.seed in Rmd file to generate random numbers, but when I knit the document I get different random numbers. Here is a screen shot for the Rmd and pdf documents side by side.
In R 3.6.0 the internal algorithm used by sample() has changed. The default for a new session is
> set.seed(2345)
> sample(1:10, 5)
[1] 3 7 10 2 4
which is what you get in the PDF file. One can manually change to the old "Rounding" method, though:
> set.seed(2345, sample.kind="Rounding")
Warning message:
In set.seed(2345, sample.kind = "Rounding") :
non-uniform 'Rounding' sampler used
> sample(1:10, 5)
[1] 2 10 6 1 3
You have at some point made this change in your R session, as can be seen from the output of sessionInfo(). You can either change this back with RNGkind(sample.kind="Rejection") or by starting a new R session.
BTW, in general please include code samples as text, not as images.
I'm starting to study assembly for PIC18f4550 and I've been trying to do some activities and I don't know how to solve it. According to the activity, Using MPLABX, I'm supposed to sum 2 16bit variables and store the result on a third 16 bit variable.
I was able to sum and store the result on the third variable but I have no idea how to declare these variables in 16bit.
; TODO INSERT CONFIG CODE HERE USING CONFIG BITS GENERATOR
INCLUDE
RES_VECT CODE 0x0000 ; processor reset vector GOTO START ; go to beginning of program
; TODO ADD INTERRUPTS HERE IF USED
MAIN_PROG CODE ; let linker place main program
START
clrw ;clear the w register
num1 equ 00000 ;declares 3 variables and their initial values
num2 equ 00001
result equ 00002
movlw H'4F'
movwf num1
movlw H'8A'
movwf num2
movf num1,W ;moves num1 value to w register
addwf num2,W ;sums num2 and w and stores it in w itself
movwf resultado ;moves w to the result register
END
I need to check if my code is actually correct (Im totally new on assembly) and how to declare these 3 variables in 16bit format. Thanks in advance!
The PIC18 is a 8 bit controller. If you want to add two 16 bit variables you had to do it byte by byte.
Maybe you don't want to work with an absolue address and work with the linker:
udata_acs H'000'
num1_LSB RES 1 ;reserve one byte on the access bank
num1_MSB RES 1 ;
You also could reserve two bytes for a name:
udata_acs H'000'
num1 RES 2 ;reserve two bytes on the access bank
Know you could access the second byte with :
movwf num1+1
And always remember to check the carry bit to get the MSB of an addition.
I am try Yowsup2 with demo EchoClient:
yowsup-cli demos -c config.example -e
I receive messages, but they are incomplete and contain strange characters at the end of each text.
For example: I send "What is your name?" from my mobile phone to Yowsup2 number, and Yowsup2 receive (and print in the terminal):
Echoing hat is your name?������������������������������������������������������������������������������������������������������������������������������������������������������������������������
Any idea?
I was working on a project using this library and i got stuck at this issue, i was waiting for someone to fix it and since no has i tried and got mine to work, this is what i did
clone the repository from github
tested to work on python3.5
in yowsup/layers/axolotl/layer.py
replace line 192 which is
191 padded.extend(self.encodeInt7bit(len(plaintext)))
192 padded.extend(plaintext) # this is the line. replace it
193 padded.append(ord("\x01"))
with this
padded.extend(plaintext.encode() if isinstance(plaintext,str) else plaintext)
add #jlguardi fix in this thread but i had to modify it a bit to work for me
def decodeInt7bit(self, string):
idx = 0
while string[idx] >= 128:
idx += 1
consumedBytes = idx + 1
value = 0
while idx >= 0:
value <<= 7
value += string[idx] % 128
idx -= 1
return value, consumedBytes
def unpadV2Plaintext(self, v2plaintext):
print(v2plaintext)
v2plaintext=bytearray(v2plaintext,'utf8') if isinstance(v2plaintext,str) else v2plaintext
end = (-(v2plaintext[-1])) # length of the left padding
length,consumed = self.decodeInt7bit(v2plaintext[1:])
return v2plaintext[1+consumed:end]
Looks clean on the client side
The garbled text though still appears on the server
not install setup.py install
Hope it works for you
I am using Pharo Smalltalk 2.0. I need to convert a float into a ByteArray. There seems to be no method to do this, is there a roundabout way of doing it?
For instance, 1 asFloat asByteArray would be perfect.
Context: I'm trying to send binary data through websocket using the Zinc Websocket package.
A Float already is a variable class, i.e. a little bit similar to an array:
3.14. "=> 3.14"
3.14 size. "=> 2"
3.14 at: 1. "=> 1074339512"
3.14 at: 2. "=> 1374389535"
You can also modify it:
| f |
f := 3.14.
f at: 1 put: 10000.
f. "=> 2.1220636948306e-310"
With that in mind, you now can handle those two integers.
However, Pharo 2.0 typically comes with Fuel pre-installed,
and it already contains means to serialize a float:
ByteArray streamContents: [ :s |
FLEncoder on: s globalEnvironment: Dictionary new do: [ :e |
3.14 serializeOn: e ]] "=> #[64 9 30 184 81 235 133 31]"
Probably, you want to use the Fuel serializing altogether, if you have Pharo or
Squeak on both ends.
If you are on i386 CPU, you can do it with native boost
(ByteArray new: 8) nbFloat64AtOffset: 0 put: Float pi; yourself
Note that byte order is littleEndian in this case.
Otherwise, you have those platform independent access:
(ByteArray new: 8) doubleAt: 1 put: Float pi bigEndian: true ; yourself
Note the difference with 0-based index for first case, and 1-based for second case.