Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Comunicados
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Bitwise operation for character

portoon
Principiante
625 Visualizações

Is there any one know that how to do bitwise operation for character?

Following is C++ code

char c;

c = '0';

c <<= 4;

to FORTRAN

character (1) c

c = '0'

c = achar(ishft(iachar(c),+4))

Is this correct ? I don't know, what to do. Please, give me some comments.

Thanks a lot.

0 Kudos
2 Respostas
anthonyrichards
Novo colaborador III
625 Visualizações
Quoting - portoon

Is there any one know that how to do bitwise operation for character?

Following is C++ code

char c;

c = '0';

c <<= 4;

to FORTRAN

character (1) c

c = '0'

c = achar(ishft(iachar(c),+4))

Is this correct ? I don't know, what to do. Please, give me some comments.

Thanks a lot.

Change the sign of the shift argument from +4 to -4. The attached demonstrates what happens by working directly with the integer equivalents to get the same answers (buildit as a console program)

program shiftbits
implicit none

Integer*1 ic, inewc
character*1 c, newc
Equivalence (c,ic), (newc,inewc)

print *, 'Hello World'

c=achar(125) ! ASCII character: close curly bracket, hex code 7D = 011111101

inewc=ishft(ic,-3) ! produces hexcode 00001111 = 0F = ASCII character 'star'
write(6,'(a5,z4,a10, z4)'),"ic = ",c,", inewc = ",newc

print *,"C = ",c,", newc = ",newc

inewc=ishft(ic,-4) ! produces hexcode 00000111 = 07 = ASCII character 'BEL' = beep
write(6,'(a5,z4,a10, z4)'),"ic = ",c,", inewc = ",newc

print *,"C = ",c,", newc = ",newc


newc=achar(ishft(iachar(c),-3)) ! produces the 'star'
print *,"C = ",c,", newc = ",newc

newc=achar(ishft(iachar(c),-4)) ! produces the 'beep'
print *,"C = ",c,", newc = ",newc

end program shiftbits

portoon
Principiante
625 Visualizações
Quoting - anthonyrichards
Change the sign of the shift argument from +4 to -4. The attached demonstrates what happens by working directly with the integer equivalents to get the same answers (buildit as a console program)

program shiftbits
implicit none

Integer*1 ic, inewc
character*1 c, newc
Equivalence (c,ic), (newc,inewc)

print *, 'Hello World'

c=achar(125) ! ASCII character: close curly bracket, hex code 7D = 011111101

inewc=ishft(ic,-3) ! produces hexcode 00001111 = 0F = ASCII character 'star'
write(6,'(a5,z4,a10, z4)'),"ic = ",c,", inewc = ",newc

print *,"C = ",c,", newc = ",newc

inewc=ishft(ic,-4) ! produces hexcode 00000111 = 07 = ASCII character 'BEL' = beep
write(6,'(a5,z4,a10, z4)'),"ic = ",c,", inewc = ",newc

print *,"C = ",c,", newc = ",newc


newc=achar(ishft(iachar(c),-3)) ! produces the 'star'
print *,"C = ",c,", newc = ",newc

newc=achar(ishft(iachar(c),-4)) ! produces the 'beep'
print *,"C = ",c,", newc = ",newc

end program shiftbits

Thanks anthonyrichards.
I saved several hours for your help.
Have a good day...!!

Responder