NewtownGuy
Technical User
Hello,
How do I arithmetic and logical operations on the bit strings that form characters ? How do I print the resulting bit-strings as characters ?
For example, suppose my perl code is passed value=CDEF, in other words, the four characters C, D, E and F. In general, I will only pass hex characters to perl because I want to operate on the four lsbs of each character to get a 4-bit hex value.
How do I extract the 4 lsbs from a character ?
How do I left-shift the 4 lsbs by 4 bits to do an unsigned multiply by 16 ?
How do I do a modulo-256 add of a series of 8-bit unsigned values ?
Do I have to do anything special to print the resulting 8-bit value as a character that is not likely to be a printable to the screen character since it can have any 8-bit value ?
For example, for the string CDEF above, I need to do this:
1) form an 8-bit value that is, in hex, 0xCD, from the first two characters, and a second 8-bit value that is, in hex, 0xEF, from the second two characters.
2) add 0xCD to 0xEF and get an 8-bit modulo-256 sum that is 0xBC, not 0x1BC.
3) print the byte 0xBC to a file.
Thank you.
How do I arithmetic and logical operations on the bit strings that form characters ? How do I print the resulting bit-strings as characters ?
For example, suppose my perl code is passed value=CDEF, in other words, the four characters C, D, E and F. In general, I will only pass hex characters to perl because I want to operate on the four lsbs of each character to get a 4-bit hex value.
How do I extract the 4 lsbs from a character ?
How do I left-shift the 4 lsbs by 4 bits to do an unsigned multiply by 16 ?
How do I do a modulo-256 add of a series of 8-bit unsigned values ?
Do I have to do anything special to print the resulting 8-bit value as a character that is not likely to be a printable to the screen character since it can have any 8-bit value ?
For example, for the string CDEF above, I need to do this:
1) form an 8-bit value that is, in hex, 0xCD, from the first two characters, and a second 8-bit value that is, in hex, 0xEF, from the second two characters.
2) add 0xCD to 0xEF and get an 8-bit modulo-256 sum that is 0xBC, not 0x1BC.
3) print the byte 0xBC to a file.
Thank you.