Here we will see a problem to shift some multi-byte BCD number to the right. The BCD numbers are shifted by two digits (8-bit). Let us consider a four-byte BCD number (45 86 02 78) is stored at location 20H, 21H, 22H, 23H. The address 10H holds the number of bytes of the whole BCD number. So after executing this code, the contents will be shifted to the right and 20H will hold 00H.AddressValue...20H4521H8622H0223H78...Program CLRA;Clear the Register A MOVR2, 10H;TakeByte Count INCR2;Increase R2 for loop MOVR1, ... Read More
Use the getTimeInstance() method in Java to get the time format for the locale you have set. DateFormat.FULL is a constant for full style pattern.Firstly, we will create Date objectDate dt = new Date(); DateFormat dateFormat;Let us format time for different locale with DateFormat.FULLdateFormat = DateFormat.getTimeInstance(DateFormat.FULL, Locale.CHINESE); System.out.println("Locale CHINESE = " + dateFormat.format(dt)); dateFormat = DateFormat.getTimeInstance(DateFormat.FULL, Locale.CANADA); System.out.println("Locale CANADA = " + dateFormat.format(dt)); dateFormat = DateFormat.getTimeInstance(DateFormat.FULL, Locale.ITALY); System.out.println("Locale ITALY = " + dateFormat.format(dt));The following is an example −Example Live Demoimport java.text.DateFormat; import java.util.Date; import java.util.Locale; public class Demo { public static void main(String args[]) { Date dt ... Read More
In this problem, we will see how to convert an 8-bit binary number to its BCD equivalent. The binary number is stored at location 20H. After converting, the results will be stored at 30H and 31H. The 30H will hold the MS portion, and 31H will hold the LS portion. So let us assume the data is D5H. The program converts the binary value of D5H to BCD value 213D.AddressValue...20HD521H...ProgramMOVR1, #20H;Takethe address 20H into R1 MOVA, @R1;Takethe data into Acc MOVB, #0AH;LoadB with AH = 10D DIVAB ;DivideA with B MOVR5, B;Storethe remainder MOVB, #0AH;LoadB with AH = 10D DIVAB ;DivideA ... Read More
In this problem, we will see how to convert 8-bit BCD number to its Binary (Hexadecimal)equivalent. The BCD number is stored at location 20H. After converting, the results will be stored at 30H.So let us assume the data is D5H. The program converts the binary value ofD5H to BCD value 213D.AddressValue...20H9421H...Program MOVR0, #20H; Initialize the address of the data MOVA, @R0;Get the data from an address, which is stored in R0 MOVR2, A; Store the content of A into R2 CLRA;Clear the content of A to 00H MOVR3, #00H LOOP: ADDA, #01H;increment A ... Read More
Now we will see how to convert Hexadecimal number to its ASCII equivalent using 8051. This program can convert 0-9 and A-F to its ASCII value. We know that the ASCII of number 00H is 30H (48D), and ASCII of 09H is39H (57D). So all other numbers are in the range 30H to 39H. The ASCII value of 0AH is 41H (65D) and ASCII of 0FH is 46H (70D), so all other alphabets (B, C, D, E) are in the range 41H to 46H.Here we are providing hexadecimal digit at memory location 20H, The ASCII equivalent is storing at location 30H.AddressValue...20H0EH21H...ProgramMOVR0, ... Read More
In this section, we will see some bit manipulation operation using 8051. The 8051 supports some operations on different bits of an 8-bit number. The operations are like complementing, setting to 1, moving, ANDing, ORing etc.In this example, we are taking a number AEH from location 10H, then after performing following bit related operations on that data, we are just storing the result at location 30H.The bit related operations that will be performed on that data, are as follows −Complement bit b2Move b5to b4OR b0and complement of b1 and store to C (b7)Set b6Reset bit b3Input is AEHBitPositionb7b6b5b4b3b2b1b0Value10101110OutputBitPositionb7b6b5b4b3b2b1b0Value01110010The output will be ... Read More
To format date, let us see the DateFormat.SHORT as well as DateFormat.LONG constants. Both of them displays different patterns.Here, we are formatting dates with getDateTimeInstance() method. Use the method to get a date and time format.For DateFormat.SHORT constant −DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); System.out.println(dateFormat.format(calendar.getTime()));For DateFormat.LONG constant −dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG); System.out.println(dateFormat.format(calendar.getTime()));The following is an example −Example Live Demoimport java.text.DateFormat; import java.util.Calendar; public class Demo { public static void main(String s[]) { Calendar calendar = Calendar.getInstance(); // for SHORT date-time DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); System.out.println(dateFormat.format(calendar.getTime())); ... Read More
We have already seen how to convert Hexadecimal digit to its ASCII equivalent. In this section, we will see how to convert two-byte (4-digit) Hexadecimal number to ASCII. Each nibble of these numbers is converted to its ASCII value.We are using one subroutine to convert a hexadecimal digit to ASCII. In this program, we are calling the subroutine multiple times.In the memory, we are storing 2-byte Hexadecimal number at location 20H and 21H. After converted ASCII values are stored at location 30H to 33H.The hexadecimal number is 2FA9H. The ASCII equivalent is 32 46 41 39.AddressValue...20H2FH21HA9H...30H00H31H00H32H00H33H00H...Program MOVR0, ... Read More
This is one of the methods of representing signed integers in the computer. In this method, the most significant digit (MSD) takes on extra meaning.If the MSD is a 0, we can evaluate the number just as we would interpret any normal unsigned integer.If the MSD is a 1, this indicates that the number is negative.The other bits indicate the magnitude (absolute value) of the number.If the number is negative, then the other bits signify the 1's complement of the magnitude of the number.Some signed decimal numbers and their equivalent in 1's complement notations are shown below, assuming a word ... Read More
If a method is declared as static, it is a member of a class rather than belonging to the object of the class. It can be called without creating an object of the class. A static method also has the power to access static data members of the class.A static variable is a class variable. A single copy of the static variable is created for all instances of the class. It can be directly accessed in a static method.An abstract class in Java is a class that cannot be instantiated. It is mostly used as the base for subclasses to ... Read More