Posts

Showing posts from November, 2021

Converting Negative Decimal To Binary

Answer : You're confused because you forgot that there must be something that distinguishes positive numbers from negative ones. Let's say you want to store non-negative numbers on 8 bits. 00000000 is 0, 00000001 is 1, 00000010 is 2, 00000011 is 3, 00000100 is 4, ... 11111111 is 255 So you can store numbers in range 0-255 on 8 bits. 255 = 2 8 - 1. (2 is the base of binary system, 8 is the number of bits, 1 is subtracted because we want to count 0 in) Now, let's say you want to store negative numbers too. How can we achieve that? We can dedicate one bit for sign. If this bit is 0 then we interpret other 7 bits as a positive number, otherwise as a negative number. It's best to use most significant bit for sign because it makes some operations easier. Trivial approach: Just read a number as-is: 00000001 == 1 and 10000001 == -1 01000010 == 66 and 11000010 == -66 01111111 == 127 and 11111111 == -127 Ones' complement: For any number x , negating its bin

Entity Framework Update Multiple Records At Once Code Example

Example: update multiple records with entity framework using ( var dbcontext = new MyModel ( ) ) { var matchedRecords = dbcontext . DummyTable . Where ( e => e . code . Equals ( entry . code ) && e . isValid . Equals ( true ) ) . ToList ( ) ; matchedRecords . ForEach ( e => e . isValid = false ) ; dbcontext . SaveChanges ( ) ; }

Flutter Change Textformfield Input Border Color Code Example

Example: change border color of TextField in flutter TextFormField ( decoration : InputDecoration ( labelText : "Resevior Name" , fillColor : Colors . white , focusedBorder : OutlineInputBorder ( borderSide : const BorderSide ( color : Colors . white , width : 2.0 ) , borderRadius : BorderRadius . circular ( 25.0 ) , ) , ) , )

Discord Snake Game Code Example

Example 1: how to make a snake game dont ask me , how would I know ? Example 2: snake game So you dont like playing the classic version of the snake game huh ?

Alternative To 2b2t Code Example

Example: 2b2t alternatives //9b9t, its a good one

Arduino Switch Case If Else Code Example

Example: arduino switch case switch ( var ) { case label1 : // statements break ; case label2 : // statements break ; default : // statements break ; }

Copy Multiple Local Files To Docker Container

Answer : There is a proposal for docker cp to support wildcards (7710), but it is not implemented yet. So that leaves you with bash scripting, using docker cp for each file: for f in data/*txt; do docker cp $f sandbox_web_1:/usr/src/app/data/; done The following command should copy whole directory data with its content of a data directory to your desired destination: docker cp data/ sandbox_web_1:/usr/src/app/ Tested on Docker version 1.12.1, but I haven't found any changes to a cp command in a the release 1.12.1 I am on Docker version 18.09 and found that I was able to copy all the files from my current local directory to the container's root by running: docker cp ./ image_name:

Amd Ryzen 5 3500u Vs I5 10th Gen Code Example

Example: ryzen 5 vs intel i5 10th gen AMD won by 1 point overall they all are dope

How To Check Postgres Version Code Example

Example 1: check postgres version psql --version Example 2: check postgres version in ubuntu $ locate bin/postgres /usr/lib/postgresql/ 9.3 /bin/postgres Example 3: get postgres version postgres -V // or psql --version Example 4: postgresql version command # SSH psql --version # SQL SELECT version ( ) ; Example 5: postgres version command SELECT version ( ) ;

All Keycodes Unity Code Example

Example 1: unity keycode if ( Input . GetKeyDown ( KeyCode . A ) ) { Debug . Log ( "The A key was pressed." ) ; } Example 2: unity getkey keycode Input . GetKey ( KeyCode . Space ) )

Aes Encryption Example Python

Example: python AES from Crypto . Cipher import AES import binascii , os import random , string iv = os . urandom ( 16 ) aes_mode = AES . MODE_CBC key = '' . join ( random . choice ( string . ascii_uppercase + string . ascii_lowercase + string . digits ) for _ in range ( 16 ) ) print ( key ) encryptor = AES . new ( key , aes_mode , iv ) def aes_encrypt ( plaintext ) : plaintext = convert_to_16 ( plaintext ) ciphertext = encryptor . encrypt ( plaintext ) return ciphertext def convert_to_16 ( plaintext ) : #Overcome the drawback of plaintxt size which should be multiple of len(iv) add = 16 - ( len ( plaintext ) % 16 ) return ( plaintext + ' ' * add ) Encrypted = aes_encrypt ( 'Jaisal ' ) print ( "Encrypted message :" , Encrypted )

32 Bits Max Value Code Example

Example 1: 16 bit max unsigned 16 bit = 0 - 65,535 signed 16 bit = -32,768 - 32,767 Example 2: 32 bit integer limit (2,147,483,647)10 (7FFFFFFF)16 (11111111111111111111111111111111)2

C Program Prime Number Code Example

Example 1: c program to check prime number using for loop # include <stdio.h> int main ( ) { int n , i , flag = 0 ; printf ( "Enter a positive integer: " ) ; scanf ( "%d" , & n ) ; for ( i = 2 ; i <= n / 2 ; ++ i ) { // condition for non-prime if ( n % i == 0 ) { flag = 1 ; break ; } } if ( n == 1 ) { printf ( "1 is neither prime nor composite." ) ; } else { if ( flag == 0 ) printf ( "%d is a prime number." , n ) ; else printf ( "%d is not a prime number." , n ) ; } return 0 ; } Example 2: prime number c # include <stdio.h> int main ( ) { int i , num , p = 0 ; printf ( "Please enter a number: \n" ) ; scanf ( "%d" , & num ) ; for ( i = 1 ; i <= num ; i ++ ) { if

Stroke Gradient Css In And Background Image Code Example

Example 1: css gradient border box-sizing : content-box ; border-width : 8 px ; border-style : solid ; border-image : linear-gradient ( to right bottom , #260B3C , #a053df ) ; border-image-slice : 1 ; Example 2: border gradient css @import url ( '//raw.githubusercontent.com/necolas/normalize.css/master/normalize.css' ) ; html { /* just for showing that background doesn't need to be solid */ background : linear-gradient ( to right , #DDD 0 % , #FFF 50 % , #DDD 100 % ) ; padding : 10 px ; } .grounded-radiants { position : relative ; border : 4 px solid transparent ; border-radius : 16 px ; background : linear-gradient ( orange , violet ) ; background-clip : padding-box ; padding : 10 px ; /* just to show box-shadow still works fine */ box-shadow : 0 3 px 9 px black , inset 0 0 9 px white ; } .grounded-radiants ::after { position : absolute ; top : -4 px ; bottom : -4 px ;