- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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...!!
I saved several hours for your help.
Have a good day...!!

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page